Forum Discussion
I need to stop/start the service using javascript , I found this in testcomplete but it is using jscript. When I ran this I got an invalid parameter error. Can you help me convert this to javascript? I tried the suggestion in the thread as well to convert it somehow to javascript but got the not authorized error
function fn_GetService(computerName, serviceName)
{
var wmiService, objectsList, eObjectsList, item, sysID;
wmiService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" +
computerName + "\\root\\cimv2");
objectsList = wmiService.InstancesOf("Win32_Service")
if (objectsList.Count > 0) {
eObjectsList = new Enumerator(objectsList);
for (; !eObjectsList.atEnd(); eObjectsList.moveNext()) {
item = eObjectsList.item();
if (item.Name == serviceName)
return item;
}
}
return null;
}
I appreciate your help. Thanks
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);
}.
- CSL9 years agoContributor
Thank you Robert, let me try.
- CSL9 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?
- CSL9 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!