camilla Posted February 6, 2014 Share Posted February 6, 2014 Hello everybody, i cannot get the logic to do this: - get the pid of a running app -stor it in a variable $iPID $iPID = WinGetProcess("[class:MozillaWindowClass]") this will do the first thing but the problem i want to compare it with another pid of the same application after a wihle to see if the pid has been changed or not - if it doesn't change exit - if it changed than compare it to the first pid any help Link to comment Share on other sites More sharing options...
jchd Posted February 6, 2014 Share Posted February 6, 2014 A new PID is assigned every time a new process is launched, irrespective of what application is launched. Hence rerun $iPID = WinGetProcess("[class:MozillaWindowClass]") every time you suspect it could have changed. What is the point of "comparing" in "if it changed than compare it to the first pid"? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
camilla Posted February 6, 2014 Author Share Posted February 6, 2014 A new PID is assigned every time a new process is launched, irrespective of what application is launched. the point is in your answer to know if the app has been closed or not . forthat i want to get the first PID than compare it to another pid of the app if they are equal exit if the are not then msg introducing the new pid Link to comment Share on other sites More sharing options...
Unc3nZureD Posted February 6, 2014 Share Posted February 6, 2014 Global $oPID = WinGetProcess("[class:MozillaWindowClass]") While 1 $nPID = WinGetProcess("[class:MozillaWindowClass]") If $nPID <> $oPid Then MsgBox(64, "Info", "The PID Has been Changed. I will quit.") Exit EndIf WEnd Maybe something like this? Link to comment Share on other sites More sharing options...
jchd Posted February 6, 2014 Share Posted February 6, 2014 So what's wrong with what I said, examplified by the post just made? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
camilla Posted February 6, 2014 Author Share Posted February 6, 2014 Unc3nZureD thank you i will test it but if i want to test the change of the pide 3 times for example take the first pid as refernce $pid1 if it changed take the new pid as refernce $pid2 if the second pid $pid2 changed compare it to the third pid $pid3 i'm just learning and i'm new to autoit i get this idea and i want to realize it Link to comment Share on other sites More sharing options...
FireFox Posted February 6, 2014 Share Posted February 6, 2014 Hi, A PID (Process Identifier) is unique, so you won't have the same. Hence I don't see the purpose to compare the PIDs. Br, FireFox. Link to comment Share on other sites More sharing options...
camilla Posted February 6, 2014 Author Share Posted February 6, 2014 FireFox. Hence I don't see the purpose to compare the PIDs. the point is in your answer to know if the app has been closed or not Link to comment Share on other sites More sharing options...
FireFox Posted February 6, 2014 Share Posted February 6, 2014 Well, just compare the new PID with the old one, like in the example posted. Br, FireFox. Link to comment Share on other sites More sharing options...
Unc3nZureD Posted February 6, 2014 Share Posted February 6, 2014 Then just modfiy the example above. Use your logic. So. You're checking if it changed or not. If it changed then set the default comparing $oPID to the $nPID, since this time it'll be the next. But you have to cont it too! Then make a new variable for counting purposese. For example $count. After setting the $oPID to the new one, then increase the $count by one ( += 1 ) Link to comment Share on other sites More sharing options...
camilla Posted February 6, 2014 Author Share Posted February 6, 2014 Unc3nZureD thank you very much i will play with the logic Link to comment Share on other sites More sharing options...
jdelaney Posted February 6, 2014 Share Posted February 6, 2014 (edited) Use winlist, and convert the hwnd's returned in the array to a PID (_winapi function out there). Loop through your, now, array of pids, and verify that YOUR PID is present or not. Your route is only checking that the first instance of class:MozillaWindowClass is not present. Edit: on launch of firefox, it spawns a new process (so the original Run PID is not present for long), so my suggestion would not work...but this works, generally: #include <WinAPI.au3> ; example of waitin for the second instance to close Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe") $ipid = Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe") Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe") MsgBox(1,1,$ipid) Sleep(5000) MsgBox(1,1,ProcessExists($iPid)) While True $aWinList = WinList("[CLASS:MozillaWindowClass]") $bExists = False For $i = 1 To UBound($aWinList)-1 Local $iTempPID="" _WinAPI_GetWindowThreadProcessId($aWinList[$i][1],$iTempPID) If $iTempPID=$ipid Then $bExists = True ; PID still exists ExitLoop EndIf Next If Not $bExists Then ExitLoop WEnd Another edit: all the PID's for ANY firefox launched will be the same...you will need to use handles to validate the window is no longer present. Edited February 6, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
camilla Posted February 6, 2014 Author Share Posted February 6, 2014 (edited) jdelaney thank you for you help,but i will tell you my idea my idea is about the possibilities of exucuting an application after 3 times of pc reboot. because the only thing that changed after each reboot is the apps PID i get the idea of taking the PID of windows explorer "[CabinetWClass]" because it is the only process that alawys works and have a window handle here we come to my script : -first we take the first $Pid1 as reference to first reboot -after 1 reboot we compare a second $Pid2 with the first one $Pid1 if they are different this means the computer has been rebooted here we take the second $Pid2 as refernce after a second reboot we take a third $Pid3 and again compare it to the second one $Pid2 if they are different this means the computer has been rebooted now we give a message box telling how many times the computer has been rebooted i cannot get the logic to do this only Edited February 6, 2014 by camilla Link to comment Share on other sites More sharing options...
Unc3nZureD Posted February 6, 2014 Share Posted February 6, 2014 What if you restart the explorer.exe because something freezed it? Link to comment Share on other sites More sharing options...
camilla Posted February 6, 2014 Author Share Posted February 6, 2014 Unc3nZureD what do you mean? Link to comment Share on other sites More sharing options...
jdelaney Posted February 6, 2014 Share Posted February 6, 2014 Seems like it would be easier to have a startup job, that write the date time to a file. If over 3 lines in the file, do something, delete the file. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
camilla Posted February 6, 2014 Author Share Posted February 6, 2014 jdelaney thank you i did that,but if we can make the script writes each time it starts and save it inside itself then when we reach 3 times it pops a message Link to comment Share on other sites More sharing options...
Unc3nZureD Posted February 6, 2014 Share Posted February 6, 2014 The problem is that it will bea quite easy to bypass If you write it into the starup, it takes 3 click to remove If you use registry, it can be sniffed and midified to have unlimited restart. Link to comment Share on other sites More sharing options...
camilla Posted February 6, 2014 Author Share Posted February 6, 2014 i don't care about its remove rather than get it to work first Link to comment Share on other sites More sharing options...
kylomas Posted February 7, 2014 Share Posted February 7, 2014 camilla, Do you want to limit the 3 starts test to a certain duration, eg; 3 starts within 5 hours? Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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