I've seen the code for jscript and vb, I tried pasting the jscript version into a script and referencing that via "Run Script Routine", entering computer and service name...
When testcomplete tries to execute this section, I get the following error.
wmiService = GetObject("WinMgmts:{impersonationLevel=impersonate}!\\\\" +
computerName + "\\root\\cimv2");
I noticed on the help page it mentions I need to set WMI security permissions, and I did set those permissions as well. Do I need to change anything in this section? Tried changing computerName to my actual computer name but no dice
Let's see your copy of the code please.
had to split it up due to character limit, but this is what I found on smartbear website
function Test() { StopService(".", "TestComplete 7 Service"); Delay(10000); StartService(".", "TestComplete 7 Service"); } function StartService(computerName, serviceName) { var service = GetService(computerName, serviceName); if (service == null) { Log.Warning("The " + serviceName + " service on the " + computerName + " computer was not found"); } else { service.StartService(); } }
function StopService(computerName, serviceName) { var service = GetService(computerName, serviceName); if (service == null) { Log.Warning("The " + serviceName + " service on the " + computerName + " computer was not found"); } else service.StopService(); }
function 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; }
Well, yes, I saw it on SmartBear, but I wanted to see exactly what you are trying to run in case there is a typo or something. 😉
thanks for the response
I think that's my question, I'm just using that code as pasted above, only thing I've tried changing is the "computerName" and "serviceName" sections with my computer name and service name.
Is there anything else I'm supposed to change? Do I need to change any part of the wmiService section?
Hi LAB,
It looks like you are using JavaScript (not JScript), which does not have JScript's GetObject() function. You need to replace GetObject() with
wmiService = Sys.OleObject("WbemScripting.SWbemLocator").ConnectServer( params )
See SWbemLocator.ConnectServer method in MSDN.
Also check out this thread:
Tried that change but testcomplete was unable to parse that line of code... checked the link provided and tried changing to this instead
function GetService(computerName, serviceName)
{
var wmiService, objectsList, eObjectsList, item, sysID;
var locator = Sys.OleObject("WbemScripting.SWbemLocator");
var objSWbemServices = locator.ConnectServer(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;
}
really feels like I'm going down the rabbit hole, error on run is now:
---------------------------
TestComplete
---------------------------
JavaScript runtime error.
TypeError
Cannot read property 'InstancesOf' of undefined
Error location:
Unit: "storecallvariables\ValidateErrors\Script\Unit2"
Line: 36 Column: 27.
---------------------------
OK
---------------------------
Your variable names are mixed up:
var objSWbemServices = locator.ConnectServer(computerName, "\\root\\cimv2"); objectsList = wmiService.InstancesOf("Win32_Service");
User | Count |
---|---|
7 | |
5 | |
2 | |
1 | |
1 |
Subject | Author | Latest Post |
---|---|---|