Talk:Check whether your application is running: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
m (Reverted edits by 199.168.142.166 to last version by Kichik)
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Hello...
Sometimes, the Window class or title are not unique.
Then, you have to loop over the found handles and check the window titles one by one.
You cannot use the message <code>WM_GETTEXT</code> to retrieve the window title, because it does not return a window title if the window has been created by another process than the owner of the current process. In this case, you have to use <code>GetWindowText</code>. [1]


First of all Thanks for the plug in.
Example:
I want to check my application is running or not when user runs installer.The plug in worked for me
<highlight-nsis>
loop:
  ; find first windows of class "SunAwtFrame" and store handle in $2
  FindWindow $2 "SunAwtFrame" "" 0 $1
  ; If nothing is found skip following check
  IntCmp $2 0 nothingFound
      ; try to retrieve the window title of window $2, store in $3
      System::Call /NOUNLOAD 'user32::GetWindowText(i r2, t .r3, i ${NSIS_MAX_STRLEN})'
      ; Copy the first 6 characters of $3 in $4
      StrCpy $4 $3 6
      ; Compare the 6 characters with "Matlab"
      StrCmp $4 "Matlab" foundMatlab loop
foundMatlab:
  MessageBox MB_OK "Found Matlab window, handle=$2, title=$3"
nothingFound:
</highlight-nsis>


But today i found a strange bug in this plug in..
[1] http://msdn.microsoft.com/en-us/library/aa928060.aspx
Suppose my executable name is MyApp.exe and when I use the plugin to find MyApp.exe is running or not. It was okay. But the problem if another application MyApp Daily.exe is running the the FindProcess API suceeds.
 
Thanks,
Harikrishnan

Latest revision as of 20:36, 8 December 2011

Sometimes, the Window class or title are not unique. Then, you have to loop over the found handles and check the window titles one by one. You cannot use the message WM_GETTEXT to retrieve the window title, because it does not return a window title if the window has been created by another process than the owner of the current process. In this case, you have to use GetWindowText. [1]

Example:

loop:
   ; find first windows of class "SunAwtFrame" and store handle in $2
   FindWindow $2 "SunAwtFrame" "" 0 $1
   ; If nothing is found skip following check
   IntCmp $2 0 nothingFound
      ; try to retrieve the window title of window $2, store in $3
      System::Call /NOUNLOAD 'user32::GetWindowText(i r2, t .r3, i ${NSIS_MAX_STRLEN})'
      ; Copy the first 6 characters of $3 in $4
      StrCpy $4 $3 6
      ; Compare the 6 characters with "Matlab"
      StrCmp $4 "Matlab" foundMatlab loop
foundMatlab:
   MessageBox MB_OK "Found Matlab window, handle=$2, title=$3"
nothingFound:

[1] http://msdn.microsoft.com/en-us/library/aa928060.aspx