Forum Discussion
Actually, starting/stopping a windows service is simply a command line of "net start <servicename>" or "net stop <servicename>". This can be done using the WshShell.Run method (https://support.smartbear.com/testcomplete/docs/reference/program-objects/wshshell/index.html).
The way I would do it is simply something like this. FYI, this should work both for JScript as well as JavaScript:
function startService(serviceName){
WshShell.Run('net start ' + serviceName, 1, true);
}
function stopService(serviceName){
WshShell.Run('net stop ' + serviceName, 1, true);
}.
Thank you Robert, let me try.
- CSL8 years agoContributor
By the way can i use net stop remotely? I tried entering the path but failed. I need to stop & start the service remotely. Can you help?
- CSL8 years agoContributor
I also need to pass on credentials.
SO how can i use net stop to stop the service remotely with different credentials. Help please!
- tristaanogre8 years agoEsteemed Contributor
In that case, I'd suggest looking into the SC (service controller) command for this process. You should run it with elevated privileges.
As for passing in credentials, not sure how to go about that off the top of my head but I found the SC command prompt stuff (https://community.spiceworks.com/how_to/5372-remotely-start-or-stop-service-from-cmd) with a quick Google search. There should be some way of doing that as well. The key is how to run the command prompt via TestComplete... and WshShell is the way to do it.