Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send Shutdown command to process through CMD Prompt on Windows

I'm currently working as software developer and I'm using bunch of tools, so I need to close them all when finished with the work. So what I have done I have created batch file with the tskill command and list of programs that i use e.g.

tskill skype
tskill outlook
tskill devenv
tskill explorer
start explorer

There is one problem with this, changes in tools are not saved when process is killed, for exampl last project, opened files, visual positions of controls and all other stuff. These settings are saved only when you close your tool, but it's really time consuming to click each of them.

So my question is: Can I send shutdown command to software instead killing process?

Note: I need command for CMD, not programing solution, as I have mentioned above I need command like "tskill skype" which kills skype process. Windows can send this command, because when you shutting down your windows, windows is sending shutdown command to all running programs. But if can't be shutdown then windows kill process as I do it above.

Thanks in advance.

like image 557
Senad Meškin Avatar asked Jul 26 '11 13:07

Senad Meškin


2 Answers

Tested on Windows 7:

taskkill /IM notepad.exe

Note that you have to specify the .exe extension. I assume this does what you need: It doesn't simply kill the process, but sends the "shutdown" signal, which will display the "Save unsaved changes?" dialog in Notepad and other editors.

like image 71
ddso Avatar answered Oct 24 '22 22:10

ddso


If your application support the standard windows messages for it you could use rmtool to lie to the application and tell it that the computer is shutting down. See How to simulate Windows shutdown for debugging?

To script it you will need to find the PID of the process before (pslist from sysinternals give the information but you will need to parse the result).

And if they don't cleanly shutdown just do as windows do when it close : Use rmtool to ask all of them to quit nicely then 30s latter kill everyone still standing (For both outlook and devenv it might even be a little short...).

like image 44
Julien Roncaglia Avatar answered Oct 24 '22 23:10

Julien Roncaglia