Forum Discussion

steve_clarke's avatar
steve_clarke
Contributor
3 years ago

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 script works, I can see Powershell is run, but the service is not started. If I use a manual method of running the ps1 script; right-click the file, select 'Run with Powershell', the service is started successfully.

I am guessing there is some form of authority that is missing when the ps1 script is run from Test Complete, perhaps? Test Complete is started with 'Run as Administrator'.

Any help appreciated.

Cheers,

Steven.

  • 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.

  • 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.