Issue using powershell with TestComplete12
My goal is to start/stop services via powershell called from a TestComplete script (python). So I read (and attempted to apply) the info in this article to do just that:
https://support.smartbear.com/viewarticle/86333/
My script which fails:
def stopLogServ(): WshShell.Run("start-process powershell.exe -verb runAs \"sc.exe stop asiLOGSERVER\"") WshShell.Run("start-process powershell.exe -verb runAs \"sc.exe stop asiLOGGER\"")
^Python interpeter returns "The System cannot find the file specified."
Everything works fine if I copy and paste the same script lines into a powershell prompt and execute them by hand. It simply does not work in TestComplete.
Thoughts, help on a resolution? Seems like this should be a common problem, just not sure how to fix.
Thanks,
John
I tried this and it worked, probably because it uses the windows native command shell instead of powershell:
def stopLogServ(): Sys.OleObject["WScript.Shell"].Run("sc.exe stop asiLOGSERVER") Sys.OleObject["WScript.Shell"].Run("sc.exe stop asiLOGGER")
Your suggestion to use this works as well:
WshShell.Run("net stop asiLOGSERVER")
I realized this morning that I was running TestComplete in administrator mode which is why the above works.
Powershell with equivalent commands (sc.exe stop asiLOGGER) and TestComplete running in admin mode just throws access denied errors. Must be something different in how the powershell session is started from TestComplete.
When I restart TestComplete without checking the box for administrator mode, the above commands fail. So I'll just run TestComplete in adminstrator mode and not use powershell with commands that need elevated permissions.