Sign in to follow this  
Followers 0
r4b1dm0nk3y

Automate Service Stop/Start

3 posts in this topic

Hi all,

I'm looking to convert a batch script into AutoIT. Basically this script checks the state of the service, then stops it if it is running or starts if stopped. Below is the batch code. I'm not looking to do a _RunDOS or Run() function but to have a true AutoIT script. I'm new to AutoIT but I want to start off good and proper. I'm planing to integrate this somehow to another .au3 which I've created to execute mouse clicks. Any help is appreciated.

@echo off

FOR /F "tokens=1,2,3,4" %%A IN ('SC.EXE QUERY "<Service Name Here>" ^| FIND /I "STATE"') DO SET STATE=%%D
IF /I "%STATE%"=="RUNNING" (NET STOP "<Service Name Here>") ELSE (NET START "<Service Name Here>")


FOR /F "tokens=1,2,3,4" %%A IN ('SC.EXE QUERY "<Service Name Here>" ^| FIND /I "STATE"') DO SET STATE=%%D
IF /I "%STATE%"=="RUNNING" (NET STOP "<Service Name Here>") ELSE (NET START "<Service Name Here>")


FOR /F "tokens=1,2,3,4" %%A IN ('SC.EXE QUERY "<Service Name Here>" ^| FIND /I "STATE"') DO SET STATE=%%D
IF /I "%STATE%"=="RUNNING" (NET STOP "<Service Name Here>") ELSE (NET START "<Service Name Here>")

Share this post


Link to post
Share on other sites



Here

Also welcome!

Share this post


Link to post
Share on other sites

Thanks Cybergon.

I don't know if that will work though. Correct me if I'm wrong but that script will only suspend and resume a process. That is not the same as starting and stopping the service correct? If my service parses files in a directory upon start, If I suspend it and resume it will it parse those files again as if the process has just been started? Perhaps thats a question for the software developer but I guess my underlying question is does suspending and resuming act the same as stopping and starting?

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