Summary
This article provides sample code illustrating how tostart or stop a service, and wait for it to completly start or stop.Synopsis
The Start, Stop, Pause Windows Service action in IA may not wait until a service is completely started or stopped before advancing to the next action. This article provides sample code illustrating how tostart or stop a service, and wait for it to completly start or stop.Discussion
The code which follows can be used in the install or uninstall method of a custom code action.
//This code will start a windows service, and ensure that it is completely started
try {
String name = ip.substitute("$SERVICE_NAME$"); // replace with internal name of service
Win32Service win32Service = (Win32Service) ip.getService(Win32Service.class);
if (win32Service.serviceExists(name)){
win32Service.startNTService(name, null);
NTServiceStatus status = win32Service.queryNTServiceStatus(name);
while(status.getCurrentState() != NTServiceStatus.SERVICE_RUNNING) {
//wait one second, then check status of service again
try {
Thread.sleep(1000);
System.out.println("waiting for " + name + " service to start");
}catch (InterruptedException e) {}
status = win32Service.queryNTServiceStatus(name);
}
}
} catch (Throwable e) {
//noop;
}
Similar code can be used to stop a service, and wait for it to stop completely.
try {
String name = ip.substitute("$SERVICE_NAME$"); // replace with internal name of service
Win32Service win32Service = (Win32Service) ip.getService(Win32Service.class);
if (win32Service.serviceExists(name)){
NTServiceStatus status = win32Service.controlNTService(name,
Win32Service.SERVICE_CONTROL_STOP);
while(status.getCurrentState() != NTServiceStatus.SERVICE_STOPPED) {
//wait one second, then check status of service again
try {
Thread.sleep(1000);
System.out.println("waiting for " + name + " service to stop");
}catch (InterruptedException e) {}
status = win32Service.queryNTServiceStatus(name);
}
}
} catch (Throwable e) {
//noop;
}
Additional Information
For information on including the InstallShield Services in a project, and compiling custom code which uses these services, see Related KB, HOWTO: Calling InstallShield Multiplatform API's in InstallAnywhereWas this helpful?
Related Articles
HOW TO: Stop a Windows Service using a Custom Action 8Number of Views Create and Register a Windows Service through Custom Code 6Number of Views HOW TO: Stop a Windows Service from Starting Automatically During Install 4Number of Views Enumerating InstallAnywhere Variables at Run Time Using Custom Code Action 6Number of Views HOW TO: Launch a bat file from INSTALLDIR/SUPPORTDIR using Custom Action 24Number of Views
Revenera Assistant
Online
Hi, I am Reva - Ask me anything.
Updates
No new updates
Chat
Home
Updates
/**/
Thanks for the feedback!
Your feedback has been saved.Rate this response:
1
2
3
4
5
Add Additional feedback ( Optional )
0/240
English
English
Language changed successfully
Something went wrong
Email sent successfully
Something went wrong
Case create successfully
Are you sure you want to cancel
the case creation?
Please select a product to submit the case.
Please select a product version to submit the case.
0/255
Upload Attachment
File Upload
Maximum file
size allowed is 3 MB.
File type
not supported.
Supported file types:
Documents (.txt, .doc, .docx, .pdf), Images (.jpg, .png), Comma Separated Files
(.csv) Speadsheets (.xlsx, .xls)
Are you sure you want to cancel the case creation?
Case closed successfully
File Upload
Maximum file size allowed is 3 MB.
File type not supported.
Supported file types:
Documents (.txt, .doc, .docx, .pdf), Images (.jpg, .png), Comma Separated Files
(.csv) Speadsheets (.xlsx, .xls)
Are you sure you want to close this case
| Products | Region | Phone Numbers |
|---|---|---|
| FlexNet Operations FlexNet Embedded FlexNet Publisher FlexNet Connect FlexNet Code Insight InstallAnywhere InstallShield |
North America * |
+1 630-332-2513 (toll) +1 877-279-2853 (toll-free in North America) |
| Europe * |
+44 1925 944367 (toll) +44 800 047 8642 (toll-free in Europe) |
|
| Japan * | +81 3-4540-5335 (select option 2) | |
| Australia * |
+61 3 9895 2177 +61 1800 560 603 (toll-free in Australia) |
|
|
Usage Intelligence (formerly
Revulytics) Compliance Intelligence |
Please use the Case Portal to submit your support ticket or reach out to your Revenera contact. | |
File Upload
Maximum file
size allowed is 3 MB.
File type
not supported.
Supported file types:
Documents (.txt, .doc, .docx, .pdf), Images (.jpg, .png), Comma Separated Files
(.csv) Speadsheets (.xlsx, .xls)
© 2026 Flexera Software. All Rights Reserved.
Case id: 00001065
Activity: Status change: 2 hours ago