Jump to content

Stop and Start Services in a script


Recommended Posts

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,

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.

Link to comment
Share on other sites

  • 4 months later...

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...