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?
badtz7229Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hunartCommented:
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...

0
Kyle AbrahamsSenior .Net DeveloperCommented:
To reopen notepad you would just add a new line:

notepad.exe <filename>  

<Filename> part could be passed in as a parameter to load a file, but is not required.

For services Hunart is correct, though to add the usual format that I have found to work is

net stop "svc name"
net start "svc name"



0
bminkerCommented:
Services

net stop "print spooler"
net start "print spooler"

Notepad

TASKKILL /F /IM "notepad.exe"
"notepad"

if you wanted a different program change the notepad to something similar to

"C:\Program Files\Microsoft Office\Office12\WINWORD.EXE"

make sure you have the quotes

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

badtz7229Author Commented:
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.
0
Kyle AbrahamsSenior .Net DeveloperCommented:
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.
0
badtz7229Author Commented:
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.
0
AmazingTechCommented:
Your code needs to stop the service before it can start it.

Do a Net stop and then kill the task if it's still running then start it.

Net Stop  "TEMP Server"
TASKKILL /F /IM "temp.exe"
Net Start "TEMP Server
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.