- NSIS Discussion
- Killing a process by PID
Archive: Killing a process by PID
Ivan Andreevich
23rd January 2009 01:12 UTC
Killing a process by PID
There seem to be 4 plugins for process destruction -
1) http://nsis.sourceforge.net/Processes_plug-in
2) http://nsis.sourceforge.net/NsProcess_plugin
3) http://nsis.sourceforge.net/KillProc_plug-in
4) http://nsis.sourceforge.net/KillProcDLL_plug-in
Did I miss any?
However, none of these have an option of killing a process by PID (process id). Is there a way to do this without modifying an existing plugin?
Thanks,
Ivan
kichik
23rd January 2009 11:06 UTC
I don't know of any plug-in that would allow you to do that. I have to wonder though, why would you want to do that? In some point, you have to get that PID by its name. Why not use the name again?
Anders
23rd January 2009 12:04 UTC
thats not 100% true, some unix ported stuff put their pid in a textfile on startup. Or maybe you just had a HWND and wanted to kill its process
Ivan Andreevich
23rd January 2009 18:10 UTC
Originally posted by kichik
I don't know of any plug-in that would allow you to do that. I have to wonder though, why would you want to do that? In some point, you have to get that PID by its name. Why not use the name again?
I install and uninstall a DLL. Sometimes that DLL is in use by mmc.exe. However, that can be many things, and I just want to kill the ones using it and leave the other ones.
So far my best bet I found so far is
http://www.tech-recipes.com/rx/446/x...line_taskkill/ via nsExec
kichik
23rd January 2009 18:39 UTC
That could be so dangerous... You could find yourself killing an important system service. You should use the LockedList plug-in instead and let the user exit those programs.
LoRd_MuldeR
23rd January 2009 18:46 UTC
If you just want to kill a process by PID, you can simply call the TerminateProcess function, which is part of the Win32 API, using the NSIS System Plugin:
* http://msdn.microsoft.com/en-us/libr...14(VS.85).aspx
* http://nsis.sourceforge.net/Docs/System/System.html
No need for a special plugin. But as mentioned already, this is dangerous, if you did not obtain the PID of the target process properly. Processes tend to have different PID's each run ;)
Ivan Andreevich
23rd January 2009 18:59 UTC
Originally posted by kichik
That could be so dangerous... You could find yourself killing an important system service. You should use the LockedList plug-in instead and let the user exit those programs.
That plugin is AWESOME, thanks for pointing it out for me! I will use it for a regular installation.
However, the other part of my installation must happen unattended on a remote machine. So I still need to kill processes by PID.
LoRd_MuldeR
23rd January 2009 19:38 UTC
If you need to terminate a service, use "net.exe stop <service_name>" instead of killing a process by PID. Even if you obtained the PID by process name, your service most likely is running in "svchost.exe", so you'd have to kill ALL instances of svchost.exe. Unfortunately this way you will kill many important system services, as several services can run in one process. And you even can't now which instance of "svchost.exe" does contain YOUR service...
Also note that LockedList can work in a "silent" way !!!
LockedList::AddCaption /NOUNLOAD "*Chrome"
LockedList::AddCaption /NOUNLOAD "*Chromium"
LockedList::AddModule /NOUNLOAD "$EXEDIR\chrome.exe"
LockedList::AddModule /NOUNLOAD "$EXEDIR\chrome.dll"
LockedList::AddModule /NOUNLOAD "$EXEDIR\icudt38.dll"
LockedList::AddModule /NOUNLOAD "$EXEDIR\themes\default.dll"
LockedList::AddModule /NOUNLOAD "$EXEDIR\plugins\gears\gears.dll"
LockedList::SilentSearch
Ivan Andreevich
23rd January 2009 20:18 UTC
Originally posted by LoRd_MuldeR
If you need to terminate a service, use "net.exe stop <service_name>" instead of killing a process by PID. Even if you obtained the PID by process name, your service most likely is running in "svchost.exe", so you'd have to kill ALL instances of svchost.exe. Unfortunately this way you will kill many important system services, as several services can run in one process. And you even can't now which instance of "svchost.exe" does contain YOUR service...
Also note that LockedList can work in a "silent" way !!!
LockedList::AddCaption /NOUNLOAD "*Chrome"
LockedList::AddCaption /NOUNLOAD "*Chromium"
LockedList::AddModule /NOUNLOAD "$EXEDIR\chrome.exe"
LockedList::AddModule /NOUNLOAD "$EXEDIR\chrome.dll"
LockedList::AddModule /NOUNLOAD "$EXEDIR\icudt38.dll"
LockedList::AddModule /NOUNLOAD "$EXEDIR\themes\default.dll"
LockedList::AddModule /NOUNLOAD "$EXEDIR\plugins\gears\gears.dll"
LockedList::SilentSearch
Yeap, noticed the silent way. Not sure if it fulfills all my req's, but I'll give it a shot.
I obtain the PIDs of the processes using my dll via
http://www.tech-recipes.com/rx/679/x..._command_line/
tasklist /m name.dll
After that I can kill by PID selectively. It's not supposed to always work - i.e. if my DLL is used over network, it's svchost.exe and I cannot terminate it. However, I do want a best effort solution.