Autoxics Posted April 18, 2006 Share Posted April 18, 2006 (edited) Hello good folks! I have a problem, lets say i have a script that is called test1.exe and when i run this script it searches for another process named test2.exe for example to see if it is active and if it is not active then test1.exe quits by itself but if test2.exe is active then test1.exe script continues to run and executes its scriptfuntions that i want this test1.exe to do if/while test2.exe is running,so far i have manage to figure this part out,but i would like the script "test1.exe" to check and prevent a second copy of a process called test2.exe to run again if test2.exe is allready running. lets asume you run photoshop for example and you do you stuff in it and then somebody comes along and pushes the photoshop icon again to run it a second time while photoshop is allready running, and then it wont work couse photshop is allready running, is this possible? i know it sounds confusing but i hope you get what i mean. i have searched thrue the forum for this particular subject but i did not find a working solution for it please help me! Edited April 18, 2006 by Autoxics Link to comment Share on other sites More sharing options...
blindwig Posted April 18, 2006 Share Posted April 18, 2006 Have you looked at the ProcessExists() function? What have you tried so far? My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 18, 2006 Moderators Share Posted April 18, 2006 Look up _SingleTon() either in the search function here or in the Beta Help file. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Autoxics Posted April 18, 2006 Author Share Posted April 18, 2006 Have you looked at the ProcessExists() function? What have you tried so far? this is on a compiled script called test1.exe $g_szVersion = "Notepad 1.1" If WinExists($g_szVersion) Then Exit; It's already running AutoItWinSetTitle($g_szVersion) HotKeySet("{HOME}", "start") HotKeySet("{END}", "end") Send("{HOME}", "start") ProcessWaitClose("Notepad.exe") ProcessWaitClose("Notepad.exe", 5) I want test1.exe to prevent a second process of Notepad.exe for example or anyother file lest say i run script1.exe and it looks to see if notepad is running and if i run notepad.exe again it will shutdown the second notepad.exe process that is trying to load and i would like to do this by checking for a process name or a by the title of the window, but preferbly a process name, to prevent anyfile of a given name to run twize Link to comment Share on other sites More sharing options...
Autoxics Posted April 18, 2006 Author Share Posted April 18, 2006 Look up _SingleTon() either in the search function here or in the Beta Help file. i tried thisIf UBound(ProcessList(@ScriptName)) > 2 Then Exit but i only got this to work with my own script1.exe name, it only prevented the script1.exe to run again, but that is not what i am after i would like it to script1.exe to prevent another exe name to be running 2 times only one instance of another specific title or a process Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 18, 2006 Moderators Share Posted April 18, 2006 this is on a compiled script called test1.exe $g_szVersion = "Notepad 1.1" If WinExists($g_szVersion) Then Exit; It's already running AutoItWinSetTitle($g_szVersion) HotKeySet("{HOME}", "start") HotKeySet("{END}", "end") Send("{HOME}", "start") ProcessWaitClose("Notepad.exe") ProcessWaitClose("Notepad.exe", 5) I want test1.exe to prevent a second process of Notepad.exe for example or anyother file lest say i run script1.exe and it looks to see if notepad is running and if i run notepad.exe again it will shutdown the second notepad.exe process that is trying to load and i would like to do this by checking for a process name or a by the title of the window, but preferbly a process name, to prevent anyfile of a given name to run twizeIf it's another application other than yours, you could try something like this: http://www.autoitscript.com/forum/index.ph...ndpost&p=172318 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Autoxics Posted April 18, 2006 Author Share Posted April 18, 2006 If it's another application other than yours, you could try something like this: http://www.autoitscript.com/forum/index.ph...ndpost&p=172318 hello thank you very much, it seems like its working the way id like it to, but do i put it in the top of my script or where to make the rest of my script act as it should? Global $FirstEXE = '', $Found = '' While 1 If ProcessExists('Notepad.exe') And $Found <> 1 Then $FirstEXE = ProcessExists('Notepad.exe') $Found = 1 EndIf Local $aProcList = ProcessList('Notepad.exe') If UBound($aProcList) - 1 > 1 Then For $icount = 1 To UBound($aProcList) - 1 If $aProcList[$icount][1] <> $FirstEXE Then ProcessClose($aProcList[$icount][1]) Next EndIf Sleep(10) WEnd Link to comment Share on other sites More sharing options...
Autoxics Posted April 18, 2006 Author Share Posted April 18, 2006 i would like this part of my code to still act as it suposed to even if i use the code i showed you that worked as i hoped for Notepad is just an example here ProcessWaitClose("Notepad.exe") ProcessWaitClose("Notepad.exe", 5) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 18, 2006 Moderators Share Posted April 18, 2006 I really don't know what your saying to be honest... Just make the script I made into a Function and leave it in a loop or something... As far as the ProcessWaitClose() the script freezes there, I would just do If Not ProcessExists('exe') Then ;Do Something EndIfThat way your script can still be working (unless the pausing of the script is desired of course). Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 18, 2006 Share Posted April 18, 2006 Watch the total array of processes for a second "notepad.exe" and keep the PID of your process and close any other "notepad.exe"s. Or if you want to keep the script running one at a time, just look for more than one "test1.exe". Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 18, 2006 Moderators Share Posted April 18, 2006 Watch the total array of processes for a second "notepad.exe" and keep the PID of your process and close any other "notepad.exe"s. Or if you want to keep the script running one at a time, just look for more than one "test1.exe".The script above does that kirby:Global $FirstEXE = '', $Found = '' While 1 If ProcessExists('Notepad.exe') And $Found <> 1 Then $FirstEXE = ProcessExists('Notepad.exe') $Found = 1 EndIf Local $aProcList = ProcessList('Notepad.exe') If UBound($aProcList) - 1 > 1 Then For $icount = 1 To UBound($aProcList) - 1 If $aProcList[$icount][1] <> $FirstEXE Then ProcessClose($aProcList[$icount][1]) Next EndIf Sleep(10) WEnd Takes note of the first instance, stores that PID in global Var and then any other instances it closes keeping the original open always. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Autoxics Posted April 18, 2006 Author Share Posted April 18, 2006 (edited) I really don't know what your saying to be honest... Just make the script I made into a Function and leave it in a loop or something... As far as the ProcessWaitClose() the script freezes there, I would just do If Not ProcessExists('exe') Then ;Do Something EndIfThat way your script can still be working (unless the pausing of the script is desired of course). I got it working, i added the code that i told you worked for me, this code, but i removed the "while 1" and the "WEnd" and the "Sleep(10)) and now it closed the second window of notepad as soon as i tried to execute another instance but kept the first notepad window alive Global $FirstEXE = '', $Found = '' While 1 If ProcessExists('Notepad.exe') And $Found <> 1 Then $FirstEXE = ProcessExists('Notepad.exe') $Found = 1 EndIf Local $aProcList = ProcessList('Notepad.exe') If UBound($aProcList) - 1 > 1 Then For $icount = 1 To UBound($aProcList) - 1 If $aProcList[$icount][1] <> $FirstEXE Then ProcessClose($aProcList[$icount][1]) Next EndIf Sleep(10) WEnd I allso added this code in a nother function below in the rest of my script insted of adding it to the top where its froze my script and it did the job, thank you so much for talking the time to help me out here! Edited April 18, 2006 by Autoxics Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now