Jump to content

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


camilla
 Share

Recommended Posts

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

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)

Link to comment
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

Link to comment
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)

Link to comment
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:

Link to comment
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 )

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...