bbi
8 years agoContributor
On TC12 WMI or BulitIn GetObject does not work anymore (working in TC11)
Hello everybody,
The following code worked well untill we upgrade to TC 12.
It is not only this specific piece of code, it's all calls to GetObject which fails.
Whatever kind of call of GetObject we make, we have the error :
Error: Invalid number of parameters.
at Error (native)
Of course TC is launched with administrator rights.
Operating system is W10 Pro.
qa.services.getService = function (ServiceName, Host) { Host = CheckHost(Host); ServiceName = qa.system.checkUndefined(ServiceName, ''); var result = null; if (ServiceName != '') { try { var objSWbemServices = GetObject("winMgmts:{impersonationLevel=impersonate}!" + Host + "\\root\\cimv2"); result = objSWbemServices ? objSWbemServices.Get("Win32_Service.Name='" + ServiceName + "'") : null; } } catch(e) { qa.system.logExceptionByLevel(e, "getService(" + ServiceName + ", " + Host + ")"); } } return result; };
Any help would be greatly appriecated !
Ok, got it !
So, the correct way is to always give the username and password parameters on ConnectServer but keep them to empty string if you connect to localhost.
Here the full code of the working method:
/** * <a id="services.getService"></a> * Récupérer un objet de type Service * @function * @param {string} ServiceName - Nom du service à rechercher * @param {string} [Host=Sys.HostName] - Nom de la machine hôte sur laquelle chercher le service, par défaut c'est sur la machine courante * @param {string} [UserName=''] - Nom d'utilisateur à utiliser pour la connexion a l'objet WMI, ne doit être valorisé que pour une machine distante * @param {string} [Password=''] - Mot de passe à utiliser pour la connexion a l'objet WMI, ne doit être valorisé que pour une machine distante * @returns {object} Renvoie l'objet Service s'il a été trouvé ou <b>null</b> si aucune service correspondant trouvé. En cas d'erreur un log d'erreur est inscrit */ qa.services.getService = function (ServiceName, Host, UserName, Password) { ServiceName = qa.system.checkUndefined(ServiceName, ''); var result = null; if (ServiceName != '') { Host = CheckHost(Host); if (Host == '\\\\.') { UserName = ''; Password = '';
Host = '.'; } else { UserName = qa.system.checkUndefined(UserName, ''); Password = qa.system.checkUndefined(Password, ''); } try { var locator = Sys.OleObject("WbemScripting.SWbemLocator"); var objSWbemServices = locator.ConnectServer(Host, "\\root\\cimv2", UserName, Password); result = objSWbemServices ? objSWbemServices.Get("Win32_Service.Name='" + ServiceName + "'") : null; } catch(e) { qa.system.logExceptionByLevel(e, "getService(" + ServiceName + ", " + Host + ")"); } } return result; };Txs for helping me.