FindProcDLL plug-in

From NSIS Wiki
(Redirected from Find Process By Name)
Jump to navigationJump to search
Author: Iceman_K (talk, contrib)


FindProcDLL ©2003 by iceman_k (Sunil Kamath), based upon the FIND_PROC_BY_NAME function written by Ravi Kochhar (http://www.physiology.wisc.edu/ravi/)

Links

FindProc.zip (24 KB)

Optimized by size binaries of FindProcDll and KillProcDll are available here: KillProcDll&FindProcDll.zip (3 KB)


From Nicholas Wang (njwdm@163.com)

Current Release for unicode edition: 2009-11-13 Download: For-NSIS-Unicode


Modified version by hnedka

Original post: link

Download: forum post | direct link

Author comments: It's alpha so far, briefly tested (ANSI version not at all). For the time being I don't recommend it for any serious project.

Changes:

  • Removed support for Win9x
  • Can find 64 bit processes (no WMI)
  • Can find processes called like a short path (Program.exe / PROGR~1.EXE)
  • Excludes current process from all searches
  • Plugin size is 3.5 kB


  • You can search for an entire path (or any part of it - from the left), for example:
    FindProcDLL::FindProc "C:\Program Files\MyProg\Prog.exe"
    FindProcDLL::FindProc "C:\Program Files"


  • You can search for a subpath from the right (backslash is expected in the process path right before the searched string):
    FindProcDLL::FindProc "MyProg\Prog.exe"
    FindProcDLL::FindProc "Program Files\MyProg\Prog.exe"


  • Integrated KillProc function (all of the above updates apply to it):
    FindProcDLL::KillProc "myprog.exe"


  • Added function WaitProcEnd, which waits for a process to exit (doesn't consume any processor time, uses WaitForSingleObject):
    FindProcDLL::WaitProcEnd "myprog.exe" -1

The second parameter is timeout, if it is reached, the function returns 100 and doesn't wait for the process (recommended value is -1); if there was no process to wait for, 0 is returned, if successfully waited, returns 1.


  • Added function WaitProcStart, which waits until a certain process start (very processor-intensive, timeout is this time used for the polling interval, set at least 250 ms, 500 is better):
    FindProcDLL::WaitProcStart "myprog.exe" 300

Returns 0 on success.


All returned values go to $R0, just like in the standard version.


As of NSIS 2.46 this plugin no longer works...

Introduction

This plugin provides the ability to check if any process running just with the name of its .exe file.

  FindProc "process_name.exe"

The return code is stored in the $R0 variable.

The return codes are as follows:

  • 0 = Process was not found
  • 1 = Process was found
  • 605 = Unable to search for process
  • 606 = Unable to identify system type
  • 607 = Unsupported OS
  • 632 = Process name is invalid

Usage

Just copy the 'FindProcDLL.dll' in your NSIS plugins directory, and call the function with one of the two suggested syntax in the NSIS documentation:

  FindProcDLL::FindProc "process_name.exe"

OR

     ; Pre 2.0 syntax
    SetOutPath $TEMP
    GetTempFileName $8
    File /oname=$8 FindProcDLL.dll
    Push "process_name.exe"
    CallInstDLL $8 FindProc

$R0 will then hold the return value.

Copyright

The original source file for the FIND_PROC_BY_NAME function is included in this distribution. The file name is: exam38.cpp, and it MUST BE in this zip file. Other than that, you may use or modify this source code as you wish in any of your projects. However, you MUST include this file as well as the exam38.cpp file if you are distributing the original or modified source to anyone or anywhere.

Thanks

Ravi for the FIND_PROC_BY_NAME function. DITMan for his KillProcDLL_Manual Manual NSIS Plugin which inspired this plugin.