Sign in to follow this  
Followers 0
camilla

how to get the PID of an application after each time it changed

24 posts in this topic

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

 

Share this post


Link to post
Share on other sites



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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

 

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

Share this post


Link to post
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

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 :sweating:

Share this post


Link to post
Share on other sites

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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

 

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

Share this post


Link to post
Share on other sites

Well, just compare the new PID with the old one, like in the example posted.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

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 )

Share this post


Link to post
Share on other sites

thank you very much i will play with the logic

Share this post


Link to post
Share on other sites

#12 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

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 by camilla

Share this post


Link to post
Share on other sites

What if you restart the explorer.exe because something freezed it?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

i don't care about its remove rather than get it to work first

Share this post


Link to post
Share on other sites

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

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  
Followers 0