Forum Discussion

steve_clarke's avatar
steve_clarke
Contributor
2 years ago
Solved

Run a Powershell script, to start a Windows service, from a Test Complete scripted test

Hi, I am trying to find a way to start the service of an application, to be tested (this being part of the overall test), by running a Powershell script from within the scripted test unit. The scri...
  • steve_clarke's avatar
    2 years ago

    Hi,

    I have now solved this by searching back through some similar posts.

    This was posted by Tristaanogre, back on 10-04-2017 @05:34 AM:

    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&colon;

     

    function startService(serviceName){
        WshShell.Run('net start ' + serviceName, 1, true);
    }
    
    function stopService(serviceName){
        WshShell.Run('net stop ' + serviceName, 1, true);
    }. 

    Seems that the ps1 script is not required at all.

    Cheers,

    Steven.