Jump to content
Sign in to follow this  
JuanFelipe

Help whit ProcessExists

Recommended Posts

JuanFelipe

Gentlemen Good morning, today I ask you a little help to you with a check I'm trying to do, it is I want to run a .exe that I did, what I do is that before running check if it is already that open, am using ProcessExists, but what happens is that I just to run first mistake, I tried to do it in different ways, but I'm not.

$proceso = ProcessExists("aceptar ventanas business.exe")
If $proceso > 2 Then
   MsgBox(16,"Error","Ya esta abierto")
Else
while 1
If WinExists("Recuperando los datos...")Then
WinActivate("Recuperando los datos...")
Send("{enter}")
Else
EndIf
WEnd
EndIf

 

Share this post


Link to post
Share on other sites
JLogan3o13

Your question is a bit vague; are you looking to ensure your script isn't run twice, or just making sure the program you're manipulating is already running?

If you don't want someone running your script twice, look at _Singleton in the help file.

If you're just looking to see if the external program is running, it should be a simple as something like this:

If ProcessExists(<external app process>) Then
    ;Do this
Else
    ;Do that
EndIf

 

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
JuanFelipe

 

Yes, as you write what he had done, but when I compile it to .exe and give start always tells me that is already running and do not start or first.
So I thought if I made him that if he was running more than twice gave me the error, but did not work well.
Excuse me if you think my question is vague but I was not born learned and that is why I come to this forum because of you I learned a lot.

In itself, what happens is that when you start the .exe it checks the process in TaskManager, then it is verified it and not start.

Edited by JuanFelipe

Share this post


Link to post
Share on other sites
JLogan3o13

That is where the question gets muddied; I am sure it is a language barrier issue. You say

when you start the .exe it checks the process in TaskManager, then it is verified it and not start.

Am I correct in reading it like this?

When I launch my compiled script, I would like it to ensure that there is only a single copy of the script running. If there is already a copy of the script running, the second one will exit.

 

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
JuanFelipe

Yes, what I want is that you can not run twice.
Because that generates conflicts me, if it is running display a MsgBox read:

Example: MsgBox (16, "Error", "The program is already running")

Share this post


Link to post
Share on other sites
JLogan3o13

As J1 states (and I stated in my first response) look at _Singleton in the help file.

  • Like 2

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
JuanFelipe

Thank you, you have taught me a lot and sorry if I ask questions that are very obvious to you, but there are things I do not understand the language, since I am from Colombia. Again thank you very much, it worked perfect me.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • Jake_s
      By Jake_s
      Hi All, 
       
      I am a begginer in auto it. I am trying to build simple gui that will show me if for example notepad.exe process is currently running on the system. I have built something like this, but when I execute it shows me message boxes, but I want the results to show in gui. If you can help me start with this.
       
      Thanks
       
        #include <MsgBoxConstants.au3>
      #include <GUIConstantsEx.au3>

      ActiveProcess()

      Func ActiveProcess()
      GUICreate("Act")
               ProcessExists("wuauclt.exe")

             If ProcessExists("wuauclt.exe") Then
       MsgBox($MB_SYSTEMMODAL, "", "Windows Upates are running")
           Else
       MsgBox($MB_SYSTEMMODAL, "", "Windows Updates are not running")
       EndIf
         ;Notepad

               ProcessExists("notepad.exe")

               If ProcessExists("notepad.exe") Then
      MsgBox($MB_SYSTEMMODAL, "", "Notepad is running")
              Else
      MsgBox($MB_SYSTEMMODAL, "", "Notepad is not running")
      EndIf  
       
    • therks
      By therks
      Is there any reason that ProcessExists would start returning false on a process that still .. exists?
      I'm having an issue that I'm so far unable to reproduce reliably, so this is more a general question/advice thread. I have a rather elaborate script running and interacting with a server application. Because the server can crash, one of the purposes of my script is to relaunch the server if it stops.
      I'm accomplishing this by storing the PID whenever I Run() the server, and I have an if statement with ProcessExists() in a loop to relaunch. This is a snippet:
      While 1 If Not ProcessExists($I_PID) Then _LogWrite('Process lost: ' & $I_PID) If TimerDiff($iRelaunchTimer) < 5000 Then $iRelaunchCount += 1 Else $iRelaunchCount = 1 EndIf If $iRelaunchCount <= 5 Then _LogWrite('Relaunching... (attempt ' & $iRelaunchCount & ')') _Launch() Else Local $sRelaunchExceeded = 'Relaunch looped ' & $iRelaunchCount & ' times in ' & Round(TimerDiff($iRelaunchTimer)/1000) & ' seconds. Check that server is not already running. Exiting.' _LogWrite($sRelaunchExceeded) MsgBox(0x10, $APP_NAME, $sRelaunchExceeded) ExitLoop EndIf $iRelaunchTimer = TimerInit() Else ; Do a bunch of other stuff EndIf WEnd Func _Launch() Global $I_PID = Run($SERVER_CMD, $SERVER_DIR, @SW_HIDE, $STDERR_MERGED) If @error Then MsgBox(0x10, $APP_NAME, 'Error running command:' & @LF & $SERVER_CMD & @LF & @LF & 'In directory:' & @LF & $SERVER_DIR) ; OK: 1 Exit 600 EndIf _LogWrite('Server launched (PID:' & $I_PID & ').') IniWrite($INI_FILE, 'Config', 'PID', $I_PID) EndFunc That's not really runnable, but you get the general idea. As I suggested above, the issue I'm experiencing is that sometimes ProcessExists returns false even though the process does still exist (getting the PID from the log, and checking task manager I can see it's still running with the same PID), and the server won't relaunch if it's already running. And the major problem I'm having with diagnosing this is that it happens completely intermittently. It could go for days just fine, or only hours (it's never quick though of course). The server runs on our media computer all the time and the computer and server sometimes go for a few days without being checked on, but ideally we'd like it running all the time.
      Anyway, I'm stumped, so any advice on offer will be gratefully accepted.
    • skyhigh
      By skyhigh
      I wrote a script based on a loop. I want my script to check at the start of every cycle if one or more processes are still running and responding, then react if they are no more. I can do the former using ProcessExist, but how about the latter?
      Does exist a function that verifies if a process is still responding?
      Thanks in advance
    • u01jmg3
      By u01jmg3
      HotKeySet("^``", "toggle_media_controls") ; Ctrl + ` While 1 Sleep(100) WEnd If Not ProcessExists("wmplayer.exe") And RegRead("HKCU\Software\Microsoft\MediaPlayer\Preferences", "HoverTransportsEnabled") = 1 Then ; Disable autohide controls RegWrite("HKCU\Software\Microsoft\MediaPlayer\Preferences", "HoverTransportsEnabled", "REG_DWORD", "0") EndIf Func toggle_media_controls() Local $sVar = RegRead("HKCU\Software\Microsoft\MediaPlayer\Preferences", "HoverTransportsEnabled") If ProcessExists("wmplayer.exe") Then If $sVar = 0 Then ; Enable autohide controls RegWrite("HKCU\Software\Microsoft\MediaPlayer\Preferences", "HoverTransportsEnabled", "REG_DWORD", "1") Else ; Disable autohide controls RegWrite("HKCU\Software\Microsoft\MediaPlayer\Preferences", "HoverTransportsEnabled", "REG_DWORD", "0") EndIf EndIf EndFunc How do I amend this code so that without pressing a hotkey, after Windows Media Player is not running, the regkey above is set to 0?
      My function and hotkey all work without issue
×