Archive: LockedList plugin and FindProcess macros


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}


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


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!


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 ;)

Yes that looks right Zinthose. I guess you don't need _a or _b any more.

Stu


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


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


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

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!


Should be fixed now.

Stu


Thanks! Please let me know when the plugin is fixed and I will test it again.


When I said it should be fixed now I had already uploaded it (v1.7 RC4).

Stu


Ya, you were just to fast with fixing and uploading...

Now everything looks as expected!

Thanks!