Link to home
Start Free TrialLog in
Avatar of tesmc
tesmcFlag for United States of America

asked on

how to end & restart process via a batch file.

I want a simple batch file that will kill a process and then restart that same process.
right now i'm doing it via 'services' window but i want it via a batch file.
i'm testing this with notepad.exe before moving forward with an actual service. not sure if coding would be diff with a service versus an application.

but for my notepad test i have

TASKKILL /F /IM "notepad.exe"

this kills notepad, but then how do i reopen a new notepad? and would these steps be same for a service?
Avatar of Member_2_957366
Member_2_957366

Taskkill will kill process by process ID.  It's useful when you wanted to kill a hung application etc...

If you would like to kill a Windows Service, use the Net Start/Net Stop/Net Restart/Net Resume etc...

SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tesmc

ASKER

bminker:
your example helped a lot. however, sometimes my process just hangs when i do it via the services window. so i have to forcefully kill it via task manager, i'm trying to incoporate using a taskkill and net start but although i'm able to successfully kill the process, i can't restart it back up

TASKKILL /F /IM "temp.exe"
Net Start "TEMP Server"

if i do this it works:
Net Stop  "TEMP Server"
Net Start "TEMP Server"

but i want to forcefully kill this service & then start it back up.
The question becomes why does your service hang?  All services should start and end gracefully.  Would recommend you write some debugging code to the sys log to find out what's going on.
Avatar of tesmc

ASKER

ged325:
sometimes it just states that the program didn't end in a timely manner and then just takes extra longer to close . that's why i wanted to just forcefully close it.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial