Jump to content

Run command keeps returning wrong PID

Recommended Posts

Hello all,

I've written the code below which launches chrome in incognito mode and then proceeds to go to the autoit website.

From my understanding, the Run() command is also supposed to output the PID number related to the application that got launched from the Run command.

However when I run the below lines, it outputs a PID number that is different from the newly launched chrome browser's PID number, does anyone know why and possibly explain how I could retrieve the accurate PID number associated with the newly launched browser?

Global $iPid = Run(@ComSpec & ' /c start chrome.exe https://www.autoitscript.com/forum/ -incognito' ,"", "")

Thank you,


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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By mLipok
      Anybody could help with using QueryInterface in AutoIt to embed Microsoft Edge using WebView2 Interface ?
      Here are links to information/documentation:

      Image comes from: https://docs.microsoft.com/en-us/microsoft-edge/webview2/media/webview2/whatwebview.png
      Introduction to Microsoft Edge WebView2

      Understand WebView2 SDK versions
      API Reference:

      I'm not WindowsApi expert (QueryInterface, C++, DllCall).
      What I trying to say is:     It means that I do not done anything in this regards .... as so far.
      2020-11-12 - Project propsed by @mLipok 2021-02-03 - First version provided by @LarsJ
    • By CarlD
      Tsk is a CLI task lister that includes PIDs, process names, hWnds and window titles. The listing can be limited by supplying a substring of the process name or window title. Here is the usage:
      TSK.exe: TaSK Lister|Switcher [CLD rev.2021-03-27] Usage ----- TSK [sub$tring] List running tasks: all tasks [tasks with process_names|window_titles matching sub$tring] TSK /SW window_title(sub$tring)|PID|hWnd Switch focus to window with matching window_title(sub$tring)|PID|hWnd TSK /?|/H Show this Help And here's the code (compiled executable is HERE):
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_type=exe #AutoIt3Wrapper_Outfile=tsk.exe #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Run_Au3Stripper=y #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; ; CLD rev.2021-03-27 AutoItSetOption("WinTitleMatchMode", -2) Global $sSub = "", $sOut = "", $iC = 0, $aW, $bSwW = 0 Global $aWinList = WinList() If $CmdLine[0] > 0 Then If StringInStr($CmdLineRaw, "/?") Or StringInStr($CmdLineRaw, "/H") Then Exit _ShowHelp() ElseIf StringInStr($CmdLineRaw, "/sw") Then $bSwW = 1 Else $sSub = $CmdLine[1] EndIf EndIf If $CmdLine[0] > 1 Then For $i = 1 To 2 If $CmdLine[$i] = "/sw" Then ContinueLoop Else $sSub = $CmdLine[$i] EndIf Next EndIf If $bSwW = 1 Then If StringInStr($sSub, "0x") = 1 Then WinActivate(HWnd($sSub)) ElseIf StringIsDigit($sSub) Then WinActivate(_GetHwndFromPID($sSub)) Else $aW = WinList($sSub) If $aW[0][0] > 1 Then WinActivate($aW[2][1]) Else ConsoleWrite("No matching window title for """ & $sSub & """" & @CRLF) EndIf EndIf Exit EndIf Global $aP = ProcessList() Global $aW[1 + $aP[0][0]][1 + $aP[0][0]] For $j = 1 To $aP[0][0] If String($aP[$j][1]) <> "" Then $aW[$j][0] = _GetHwndFromPID($aP[$j][1]) $aW[$j][1] = WinGetTitle($aW[$j][0]) Else $aW[$j][0] = "" $aW[$j][1] = "" EndIf Next Global $iX = 10 For $k = 1 To $aP[0][0] If $sSub Then If StringInStr($aP[$k][0], $sSub) = 0 Then If $aP[$k][1] Then If StringInStr($aW[$k][1], $sSub) = 0 Then ContinueLoop Else ContinueLoop EndIf EndIf EndIf If StringLen($aP[$k][0]) >= $iX Then $iX = 2 + StringLen($aP[$k][0]) Next Global $sHdr = StringFormat("%7s", "PID") & " " & StringFormat("%-" & $iX & "s", "Process") & StringFormat("%-12s", "hWnd") & "Window Title" & @CRLF For $i = 1 To $aP[0][0] If $sSub Then If StringInStr($aP[$i][0], $sSub) = 0 Then If $aW[$i][0] Then If StringInStr($aW[$i][1], $sSub) = 0 Then ContinueLoop Else ContinueLoop EndIf EndIf EndIf $iC += 1 $sOut &= StringFormat("%7s", $aP[$i][1]) & " " & StringFormat("%-" & $iX & "s", $aP[$i][0]) & StringFormat("%-12s", $aW[$i][0]) & $aW[$i][1] & @CRLF Next If $iC > 0 Then If $CmdLine[0] = 0 Then $sOut &= @CRLF & "Command " & StringUpper(StringTrimRight(@ScriptName, 4)) & StringLower(StringRight(@ScriptName, 4)) & " /? for usage" & @CRLF ConsoleWrite($sHdr & $sOut) Else ConsoleWrite("No matches" & @CRLF) EndIf Exit Func _GetHwndFromPID($PID) Local $hWnd = 0 Local $stPID = DllStructCreate("int") For $i = 1 To $aWinList[0][0] If $aWinList[$i][0] <> "" Then DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $aWinList[$i][1], "ptr", DllStructGetPtr($stPID)) If DllStructGetData($stPID, 1) = $PID Then Return $aWinList[$i][1] EndIf Next Return $hWnd EndFunc ;==>_GetHwndFromPID Func _ShowHelp() Local $sTxt = StringUpper(StringTrimRight(@ScriptName, 4)) & StringLower(StringRight(@ScriptName, 4)) & ": TaSK Lister|Switcher [CLD rev.2021-03-27]" & @CRLF & @CRLF & "Usage" & @CRLF & "-----" & @CRLF & StringUpper(StringTrimRight(@ScriptName, 4)) & " [sub$tring]" & @CRLF & " List running tasks: all tasks [tasks with process_names|window_titles matching sub$tring]" & @CRLF & StringUpper(StringTrimRight(@ScriptName, 4)) & " /SW window_title(sub$tring)|PID|hWnd" & @CRLF & " Switch focus to window with matching window_title(sub$tring)|PID|hWnd" & @CRLF & StringUpper(StringTrimRight(@ScriptName, 4)) & " /?|/H" & @CRLF & " Show this Help" ConsoleWrite($sTxt & @CRLF) EndFunc ;==>_ShowHelp  
    • By emendelson
      I have a script that runs another application (vDos.exe), and the same script can be run multiple times to open other instances of the same vDos.exe application.
      When I open a new instance of vDos.exe, I want to make sure that its window does not open directly over a previous instance, so I want to get the window positions of previous instances. Has someone written a method of finding the PIDs of all instances of the same executable, so that I can get the window positions of each of them?
      I've found various application counters in the forum, but they seem to be designed to find multiple instances of the script, not of another application.
      Many thanks for any pointers.
    • By mLipok
      A new quick/small UDF.
      #include-once #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Global $RUN_WRAPPER_PID Global Enum _ $RUNWRAPPER_ERR_SUCCESS, _ $RUNWRAPPER_ERR_GENERAL, _ $RUNWRAPPER_ERR_COUNTER Global Enum _ $RUNWRAPPER_EXT_DEFAULT, _ $RUNWRAPPER_EXT_NOT_FINISHED_YET, _ $RUNWRAPPER_EXT_COUNTER If Not @Compiled And @ScriptName = 'Run_Wrapper.au3' Then _Example_for_Run_Wrapper() Func _Example_for_Run_Wrapper() _Run_Wrapper('ping') If @error then Return SetError(@error, @extended, 0) While $RUN_WRAPPER_PID Sleep(10) _Run_Wrapper_GetStdout() If @error Then _Run_Wrapper_GetStderr() If @error Then ExitLoop EndIf WEnd MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, 'Information #' & @ScriptLineNumber, _ _Run_Wrapper_GetStdout() & @CRLF & _ _Run_Wrapper_GetStderr() _ ) EndFunc ;==>_Example_for_Run_Wrapper Func _Run_Wrapper($sCommand) _Run_Wrapper_GetStdout(Null) _Run_Wrapper_GetStderr(Null) $RUN_WRAPPER_PID = Run(@ComSpec & " /c " & $sCommand, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) If @error Then Return SetError($RUNWRAPPER_ERR_GENERAL, $RUNWRAPPER_EXT_DEFAULT, 0) Return $RUN_WRAPPER_PID EndFunc ;==>_Run_Wrapper Func _Run_Wrapper_GetStdout($v_Reset = Default) Local Static $s_StdOut = "" If IsKeyword($v_Reset) And $v_Reset = Null Then $s_StdOut = '' $s_StdOut &= StdoutRead($RUN_WRAPPER_PID) If @error Then Return SetError(@error, $RUNWRAPPER_EXT_DEFAULT, $s_StdOut) Return SetExtended($RUNWRAPPER_EXT_NOT_FINISHED_YET, $s_StdOut) EndFunc ;==>_Run_Wrapper_GetStdout Func _Run_Wrapper_GetStderr($v_Reset = Default) Local Static $s_StdErr = '' If IsKeyword($v_Reset) And $v_Reset = Null Then $s_StdErr = '' $s_StdErr &= StderrRead($RUN_WRAPPER_PID) If @error Then Return SetError(@error, $RUNWRAPPER_EXT_DEFAULT, $s_StdErr) Return SetExtended($RUNWRAPPER_EXT_NOT_FINISHED_YET, $s_StdErr) EndFunc ;==>_Run_Wrapper_GetStderr  
    • By vargheseg
      I have a web page which  has  somewhere from 90-100 records any time. So one has to scroll from from certain height to bottom using scroll bar on the right or using the down key. Is there any functionality to take a single screenshot and give .jpeg file.  Any previous links or direction will be very helpful for me
      George V
  • Create New...