Simple batch script to pause/resume GPU client

drdeutsch

2[H]4U
Joined
Sep 17, 2004
Messages
3,775
I'm trying to make a simple batch script that will either Pause or resume my GPU Folding client. Sometimes if I'm trying to watch videos while it's folding, the mouse gets all jerky and annoying, so I just like to pause it while I watch and then start it up again. Should be a fairly simple script, but doesn't seem to be working.

I'm a noob and have copied most of this/adapted it from various google search pages.

Code:
@echo off
//This first line checks to see if the GPU Folding Client is running. 
//If the License server is up it's safe to assume the client is also up
NET START|FIND "Folding@home-GPU-[2]"
//Tell the script to go to the proper answer
GOTO answer%errorlevel%
//If errorlevel returned 0, the service is running so we shut it down and exit the script
:answer0
NET PAUSE "Folding@home-GPU-[2]"
EXIT
//If errorlevel returned 1, the service is down so we start it up and quit the script
:answer1
NET RESUME "Folding@home-GPU-[2]"
EXIT

Any idea what I'm doing wrong? Thanks.
 
You have to either be Administrator or have Administrator privileges (be a member of the admin group) to start/stop/pause service.

I was unable to get NET START|FIND to work on any of my running services. I could find nowhere that this is a valid command. I can see what you're trying to do and keep it all in one script/batch file but either way you're going to have to run it twice so here's what I'd do.

Use two batch files. First use NET START to get a list of all running service. Copy the name of the GPU service into your batch files to ensure you have the name correct.

I'd go on the assumption that if I wanted to play videos etc then I just want to pause the service. So I'd simply use one batch file NET PAUSE <service name> before watching videos etc. Then after I was finished I'd hit the second batch file NET START <service name> to restart the GPU client.

Not as sexy as what you were trying to do but I don't believe NET START|FIND works or will return an errorlevel so you can use it like you're thinking.

Maybe one of our resident system admins will check in and either verify this or set you straight. Either way, the two simple batch file will do the trick.
 
I do have admin privileges. I've been playing with it a bit and this is what I have:

Code:
//This first line checks to see if the GPU Folding Client is running. 
//If the License server is up it's safe to assume the client is also up
SC query Folding@home-GPU-[2] | FIND "STATE"
//Tell the script to go to the proper answer
if errorlevel==0 goto PAUSE
if errorlevel==5 goto CONTINUE
//If errorlevel returned 4, the service is running so we pause it and exit the script
:PAUSE
SC PAUSE Folding@home-GPU-[2]
EXIT
//If errorlevel returned 7, the service is paused so we start it up and quit the script
:CONTINUE
SC CONTINUE Folding@home-GPU-[2]
EXIT

Now, this works... halfway. It will successfully pause the service if it is running. However... it doesn't continue a paused service. I've tried various errorlevels, but I can't seem to get it to work.

If I go to a command prompt and type "sc continue Folding@home-GPU-[2]", it will continue the paused service. I just can't seem to get to do it in a batch script.

Maybe an if/else statement? I'm still playing around with it... if I can get halfway, I should be able to get the other half.
 
Use a Systray gpu client, click on the taskbar icon and you can pause/resume work from there without any batch file ;)
 
I could use the systray client... but now my desire to understand this damn batchscript is engulfing me.

Anyway, I've got it:

Code:
@echo off
SC query Folding@home-GPU-[2] | FIND "STATE" > GPU_Status.txt
findstr /m "RUNNING" GPU_Status.txt
IF %ERRORLEVEL%==0 GOTO PAUSE
ELSE GOTO RESUME

:RESUME
SC CONTINUE Folding@home-GPU-[2]
GOTO END

:PAUSE
SC PAUSE Folding@home-GPU-[2]
GOTO END

:END
EXIT

It does require the generation of the additional .txt file to search for the string (is it possible to do this in another IF statement so that I could avoid making the other file?) but otherwise it works great. One double-click and it's off and on.

Only took me the better part of 4 hours to figure this out. Before that, my programming experience consisted of making a C++ Hello World program in College about 8 years ago.

Yay for me!
 
I could use the systray client... but now my desire to understand this damn batchscript is engulfing me.

Nice job getting it figured out! What do they call that? Oh yeah.. persistence. :D
 
Give this a try :)
Code:
@echo off
for /f "tokens=4 delims= " %%a in ('sc query Folding@home-GPU-[2] ^| findstr /c:"STATE"') do ( 
     if "%%a"=="RUNNING" GOTO :PAUSE
     if "%%a"=="STOPPED" GOTO :RESUME
)
goto :END

:RESUME
     SC CONTINUE Folding@home-GPU-[2]
GOTO :END

:PAUSE
     SC PAUSE Folding@home-GPU-[2]
GOTO :END

:END
EXIT
 
Back
Top