Old 16th April 2008, 04:28   #1
wraithdu
Junior Member
 
Join Date: Sep 2002
Posts: 39
Process Functions Header

I've written a header file with several process related functions I wanted to see in NSIS. These were inspired by PortableApps.com where we use NSIS to script the portable launchers. My goal was to accomplish everything using only the System plugin, so there are no external dependencies. Only one alternate function requires a 3rd party plugin. I hope some other people can find this useful as well.

Download ProcFunc.nsh

${ProcessExists}
Determines if a given process exists by name or PID, and returns the Process ID (PID).

${GetProcPath}
Determines first if a process exists, and returns the full path by name or PID.

${GetProcName}
If the process exists, returns the name by PID.

${ProcessPathSearch}
Searches all running process paths for a given search term, then passes that path and the process's PID to a user defined function for processing (works like the GetDrives macro). Use .::RETURN_ALL::. as the searchterm to return all running process paths.

${ProcessWait}
Will pause script execution until the given process exists or until timeout, by name. Will poll for the process every 500ms. Returns the process's PID, or -1 if timed out.
WARNING: this function is CPU intensive on Windows Vista. I recommend using ${ProcessWait2} if the script will be in this state for an extended period of time.

${ProcessWait2}
Same as ${ProcessWait}, but requires the FindProcDLL plugin, polls every 250ms, and produces much lower CPU load on Windows Vista.

${ProcessWaitClose}
Will pause script execution until the given process no longer exists, by name or PID. Can specify a timeout value (how long to wait), or wait indefinitely. Returns the PID of the closing process if successful, -1 if timed out.

${CloseProcess}
Closes a process by name or PID by sending the WM_CLOSE message to all windows owned by the process. This is the MS recommended method for closing a process. It will give you the opportunity, for example, to save an unsaved txt file open in notepad. This command will return immediately after sending the messages, so it's advisable to check when the process actually closes, ie with ${ProcessWaitClose}. Returns the closed process's PID.

${TerminateProcess}
Forcibly closes a process by name or PID. Returns the terminated process's PID.

${Execute}
Runs a process, supports commandline arguments. Allows you to optionally specify a working directory and returns the process's PID if successful, 0 if it fails.
wraithdu is offline   Reply With Quote
Old 16th April 2008, 14:24   #2
wraithdu
Junior Member
 
Join Date: Sep 2002
Posts: 39
Oops, quick fix in my ${ProcessWait} timeout counter.
wraithdu is offline   Reply With Quote
Old 16th April 2008, 21:59   #3
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
That looks very useful and should have its own Wiki page. See the following link on creating pages on the Wiki.

http://nsis.sourceforge.net/Starting_a_new_page

It'd be worth mentioning this would only work on Windows NT and above on the Wiki page.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th January 2010, 18:59   #4
wraithdu
Junior Member
 
Join Date: Sep 2002
Posts: 39
I've updated ProcFunc to include, among other internal changes,

${GetProcessParent}
If the process exists, returns the parent process's PID.

Download ProcFunc.nsh

Project thread on PortableApps. This page will be kept up to date more so than this one.
wraithdu is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump