Windows 2008 Server, kill a process the start it again?

Karandras

[H]ard|Gawd
Joined
Feb 16, 2001
Messages
1,873
Ok here is the problem:

We have WhatsUp Gold running on this server. There is plenty of CPU and HDD power for this application (running with MS SQL 2005) but for some reason when this machine was ordered they only got 1 gig of ram....sigh. Now WhatsUp Polling engine is crashing every other night, we have another 2 gig on order to try to solve this issue. The only way to get the polling engine to start working again is to restart it. However when you try to restart in services the process is forever locked up at "Stopping". At that point you have to kill the process for WhatsUp then you can start it again

So here is what I want to do since the ram won't be here until next week. I need to make sure this thing will be running all the time. I want to restart the service at lets say 11pm nightly. How can I get Windows task scheduler to kill the process then start it again? (There is another process that needs to be stopped before we can kill this so I would be: Stop Process 1, Kill Process 2, Start Process 2, Start Process 1)

I'm sure it's easy enough to setup a start/stop service in windows task scheduler but I'm not sure what I can do to kill the process?

Thanks.
 
There used to be a utility called taskkill or something to that effect. You could create a batch file to run all of your commands, and then schedule that batch file to run at certain times.
 
Taskkill is still there.

You would use:
taskkill /im appname.exe /f (/im is the "image name" option, /f is force)
net start servicename
 
Perfect, thanks for the info.

I was trying to find a pause or a sleep time for the script for between stops and starts (in case killing the process takes longer). I couldn't find any specific command but people are using:

ping -n 11 127.0.0.1 > nul

That would wait for the timeout to happen (10 seconds) then continue the script. Not making the script too complicated is there any other commands to make the script sleep for 5 seconds?

Thanks.
 
ell I've thought about this some more and I think I want to verify that the process has stopped, and if it hasn't stopped wait until it has stopped. This would be nice and easy with bash scripting but batch...geh.

So with taskkill it does generate a SUCCESS or ERROR in it's response. Can I capture the response, parse it for SUCCESS or ERROR and halt the script or wait additional time if ERROR is given or continue if SUCCESS is given? Or should I be writing this in a different language?

Talking with the programmers here, we are going to write this in python to get it working.

thanks.
 
Last edited:
Use a PowerShell script;

while ($true) {
Restart-Service <service name>
Start-Sleep -Seconds 300
}
 
I don't believe it's possible for taskkill /f to fail. The OS kills the process without letting it shut down.

Have you considered PowerShell? PowerShell has a sleep function.

Edit: What he said :)
 
Last edited:
Schedule a powershell script to run at 11PM

Stop-Process –processname <process name>
Invoke-Expression <executable>
 
echo Starting 10 Second Sleep!
echo Wscript.Sleep 10000> sleep.vbs
start /w wscript.exe sleep.vbs
echo Done!
del sleep.vbs

Is how I sleep in batch scripts... ;)

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top