Jump to content

Recommended Posts

my workaround for now until i can learn how to code and have the commands(stop and start the service) within the AutoIT executable.

#RequireAdmin
Local $sUserName = "localAdmin"
Local $sPassword = "localAdminPW"
RunAsWait($sUserName, @ComputerName, $sPassword, 0, "C:\Directory\file.bat", @WorkingDir)

Link to post
Share on other sites

What do you mean how to start it in the same script?

Runaswait will return as soon as it is done running and you just rinse and repeat only with start this time

Local $sServiceName = "Service Name"
RunAsWait("your username", "your domain", "your password", logon_flag, @ComSpec & ' /k net stop "' & $sServiceName & '"', "workingdir" [, show_flag [, opt_flag]]] )

RunAsWait("your username", "your domain", "your password", logon_flag, @ComSpec & ' /k net start "' & $sServiceName & '"', "workingdir" [, show_flag [, opt_flag]]] )

Although it should be mentioned that it would be better to do this in a context of you having more control such as one of the Windows Service UDFs and then you could know why/when it failed

 

Link to post
Share on other sites
7 hours ago, Bilgus said:

What do you mean how to start it in the same script?

Runaswait will return as soon as it is done running and you just rinse and repeat only with start this time

Local $sServiceName = "Service Name"
RunAsWait("your username", "your domain", "your password", logon_flag, @ComSpec & ' /k net stop "' & $sServiceName & '"', "workingdir" [, show_flag [, opt_flag]]] )

RunAsWait("your username", "your domain", "your password", logon_flag, @ComSpec & ' /k net start "' & $sServiceName & '"', "workingdir" [, show_flag [, opt_flag]]] )

Although it should be mentioned that it would be better to do this in a context of you having more control such as one of the Windows Service UDFs and then you could know why/when it failed

 

Hi @Bilgus i tried that, but it opened two command windows and ran both commands at the same time. one was successful in stopping the service, the other was not successful as the service wasn't fully stopped for it to start.

thanks!!

Link to post
Share on other sites

Sorry I didn't even think of that

This goes back to 

Quote

Although it should be mentioned that it would be better to do this in a context of you having more control such as one of the Windows Service UDFs and then you could know why/when it failed

So basically runaswait returns because the command is done so you either need to Sleep() which is flaky and bad

or just have the cmd line do it

@ComSpec & ' /k net stop ' & $sServiceName & ' & net start ' & $sServiceName

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...