fawder Posted March 14, 2018 Share Posted March 14, 2018 well. i think the hard part is done. I will need to figure out how to start it in the same script Link to comment Share on other sites More sharing options...
fawder Posted March 14, 2018 Share Posted March 14, 2018 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 comment Share on other sites More sharing options...
Bilgus Posted March 14, 2018 Share Posted March 14, 2018 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 comment Share on other sites More sharing options...
fawder Posted March 14, 2018 Share Posted March 14, 2018 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 comment Share on other sites More sharing options...
fawder Posted March 14, 2018 Share Posted March 14, 2018 @Bilgus correction: i just ran it again. First window opened, stopped the service and then sits at: C:\Windows\system32> once i exit, the second line runs and starts the service. Link to comment Share on other sites More sharing options...
Subz Posted March 14, 2018 Share Posted March 14, 2018 Just replace /k with /c should fix that. fawder 1 Link to comment Share on other sites More sharing options...
Bilgus Posted March 14, 2018 Share Posted March 14, 2018 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 comment Share on other sites More sharing options...
fawder Posted March 14, 2018 Share Posted March 14, 2018 1 hour ago, Subz said: Just replace /k with /c should fix that. worked!!! ty @Subz Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now