Sign in to follow this  
Followers 0
AntonioGNAL

Stop and Start Services in a script

5 posts in this topic

Hello Everyone,

I'm creating a script to install a program and i need to apply some patches after the installation is complete. However, those patches require to stop and start some services and i'm unable to do so.

The part of the script to manage the services is as follows:

; Patches Start!
; Stop services to be able to copy the patch files
RunWait("net stop SafeCom" & "Service", @SW_HIDE)
RunWait("net stop Spooler", @SW_HIDE)
; Copy the SafeCom patches to the main directory
FileCopy($d & "\scDevUtilLib.dll", "E:\SafeComG3\", 1)
FileCopy($d & "\scMoneyServer.exe", "E:\SafeComG3\", 1)
FileCopy($d & "\scUserImportLib.dll", "E:\SafeComG3\", 1)
; Start the services to complete the process and start working
RunWait("net start Spooler", @SW_HIDE)
RunWait("net start SafeCom" & "Service", @SW_HIDE)
; Finish!

I know the files are trying to copy themselves, but the services are not stopping preventing the files from being overwritten.

Any ideas of what i'm doing wrong?

Thanks a lot.

Best regards,

Share this post


Link to post
Share on other sites



Get the return value from RunWait and see if there are any problems.

$iResult = RunWait("net stop SafeCom" & "Service", @SW_HIDE)

And shouldn't there be a space between "SafeCom" and "Service"?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I found the problem.

I can't use RunWait to stop services, but i can use it to exacute an external bat file who does. :D

; Patches Start!
$Stop = @WorkingDir & "StopServices.bat"
$Start = @WorkingDir & "StartServices.bat"
; Stop services to be able to copy the patch files
RunWait($Stop) ;, @SW_HIDE)
; Copy the SafeCom patches to the main directory
FileCopy(@WorkingDir & "scDevUtilLib.dll", "E:SafeComG3", 1)
FileCopy(@WorkingDir & "scMoneyServer.exe", "E:SafeComG3", 1)
FileCopy(@WorkingDir & "scUserImportLib.dll", "E:SafeComG3", 1)
; Start the services to complete the process and start working
RunWait($Start) ;, @SW_HIDE)
; Finish!

Problem Solved!

Thanks.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Glad you solved it. Another way you can try it though without adding a bat file to the mix is this:

RunWait(@Compsec & ' /c net stop SafeCom' & 'Service', '',@SW_HIDE)
Edited by jazzyjeff

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You can start or stop services from an AutoIT script...

RunWait(@ComSpec & " /c " & 'net start YourService', "", @SW_HIDE)

RunWait(@ComSpec & " /c " & 'net stop YourService', "", @SW_HIDE)

Edited by HorseMan

Share this post


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
Sign in to follow this  
Followers 0