- NSIS Discussion
- LockedList plugin and FindProcess macros
Archive: LockedList plugin and FindProcess macros
underline
9th July 2010 11:31 UTC
LockedList plugin and FindProcess macros
Thanks to Afrow UK for it's great LockedList plugin.
I use this plugin to find running processes using macros which can be very useful on some situations. I write next macros which seems works as expected but I still need experts confirmation if there can be any issue using it as macros.
!macro _IsProcessRunning _a _b _t _f
LockedList::FindProcess "${_b}"
Pop $R0
!insertmacro _!= $R0 "" `${_t}` `${_f}`
!macroend
!define IsProcessRunning `"" IsProcessRunning`
# and can be used as:
${If} ${IsProcessRunning} "notepad.exe"
MessageBox MB_OK "notepad is running!"
${EndIf}
Afrow UK
9th July 2010 13:09 UTC
The only problem there is if $R0 != "" then you should be doing another 2 Pop's to empty the stack. It is bad practice not to. Perhaps though I could add a /yesno switch which will just push yes or no onto the stack instead?
Stu
underline
9th July 2010 13:37 UTC
Stu, your suggestion should fix that issue. If you do it please let me know.
So based on your suggestion the macros should looks like below in order to empty the stack?
!macro _IsProcessRunning _a _b _t _f
LockedList::FindProcess "${_b}"
Pop $R0
Pop $R0
Pop $R0
!insertmacro _!= $R0 "" `${_t}` `${_f}`
!macroend
!define IsProcessRunning `"" IsProcessRunning`
Thanks!
Zinthose
9th July 2010 15:28 UTC
You also need to protect the $R0 value in case it is used prior to calling the macro.
Something like this.
!macro _IsProcessRunning _a _b _t _f
## Protect $R0
Push $R0
## Search for the process
LockedList::FindProcess "${_b}"
Pop $R0
StrCmp $R0 '' 0 +3
Pop $R0
Goto `${_f}`
## Pops unused FindProcess values from stack
Pop $R0
Pop $R0
## Restore $R0 to previous value
Pop $R0
## Process was Found
Goto `${_t}`
!macroend
!define IsProcessRunning `"" IsProcessRunning`
I haven't tested it but it looks right ;)
Afrow UK
9th July 2010 16:07 UTC
Yes that looks right Zinthose. I guess you don't need _a or _b any more.
Stu
underline
9th July 2010 20:24 UTC
Seems that LockedList::FindProcess works only if the process name is Case Sensitive else the plugin will not return the path or process description?
Just try: LockedList::FindProcess Notepad.exe
Afrow UK
10th July 2010 10:02 UTC
Ah that's a bug thanks (or rather, I'm not converting the input string to lower case). Will fix and add the /yesno switch.
Stu
Afrow UK
10th July 2010 11:07 UTC
Update the plug-in. Your macro can look like this:
!macro _IsProcessRunning _a _b _t _f
!insertmacro _LOGICLIB_TEMP
LockedList::FindProcess /yesno `${_b}`
Pop $_LOGICLIB_TEMP
!insertmacro _== $_LOGICLIB_TEMP yes `${_t}` `${_f}`
!macroend
!define IsProcessRunning `"" IsProcessRunning`
Stu
underline
10th July 2010 13:50 UTC
Stu,
Thanks for the macros!
The bug with LockedList::FindProcess Case Sensitive is not fully fixed!
Now it works with Notepad.exe process but if the running process has Uper Case letter(s) inside it's name (Example: WinRAR.exe) then the plugin will fail. Just try:
LockedList::FindProcess WinRAR.exe
LockedList::FindProcess winrar.exe
Now the running process is not detected anymore! With previous plugin were detected but no path or description returned! Now there is no detection! Please check with WinRAR.exe
Thanks!
Afrow UK
10th July 2010 14:00 UTC
Should be fixed now.
Stu
underline
10th July 2010 14:06 UTC
Thanks! Please let me know when the plugin is fixed and I will test it again.
Afrow UK
10th July 2010 16:11 UTC
When I said it should be fixed now I had already uploaded it (v1.7 RC4).
Stu
underline
10th July 2010 16:19 UTC
Ya, you were just to fast with fixing and uploading...
Now everything looks as expected!
Thanks!