Forum Discussion
Hello ,
I already refered this link.But same code i use and it not affect on the Services .
Hi,
-- Did you check in Task Manager that the relevant service process starts/stops?
-- Does the account that executes the start/stop code have anough privileges (as mentioned in the referenced article)?
-- Can you post here your actual code?
-- Any related messages in the Windows Event Viewer logs?
- CSL8 years agoContributor
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
- tristaanogre8 years agoEsteemed Contributor
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); }.
- CSL8 years agoContributor
Thank you Robert, let me try.
Related Content
- 12 years ago
- 7 years ago
- 3 years ago
Recent Discussions
- 3 days ago
- 3 days ago
- 6 days ago