Jump to content

Recommended Posts

Posted

I have multiple process with same title and class, but i edited the executable name to differ each one,  in determined actions they will run a autoit script, is possible detect the process who executed the script?

Posted

If i use winactivate will mess up everything, process exist and process list , how it can help to detect the process who executed the script.

Posted
3 minutes ago, memerim said:

If i use winactivate will mess up everything

Of course, but not WinGetProcess, WinGetHandle, WinGetText, etc.  Help file is your best friend...

Now that you have the basic tools, it is time for you to write some code. Enjoy ! 

Posted (edited)
8 minutes ago, Exit said:
ConsoleWrite(@AutoItPID & @CRLF)   ; Process identifier (PID) of the current script.

 

I think he wants to know which process launched the autoit script...

ps. another option is to pass the launcher PID as a command line parameter to the autoit script.

Edited by Nine
Posted

To find the parent process PID you can use this:

 

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)

Posted
1 hour ago, Nine said:

I think he wants to know which process launched the autoit script...

ps. another option is to pass the launcher PID as a command line parameter to the autoit script.

Exactly, i'm trying know which process launched the autoit script, and Nine, i have searched and read in the help file, this is how i did my script below.

This is my actual script, he detects the active window, get her process name, and run another script inside a determined sandboxie, im trying identify what process launched the script without needs active her window.

Local $Actwin = WinGetHandle("[ACTIVE]")
    Local $PidActwin = WinGetProcess($Actwin)
    Local $NamePidActwin = _Findpidname($PidActwin)


    If $NamePidActwin = "1.exe" Then
    Local $client= "/box:1   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "2.exe" Then
    Local $client= "/box:2   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "3.exe" Then
    Local $client= "/box:3   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "4.exe" Then
    Local $client= "/box:4   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "5.exe" Then
    Local $client= "/box:5   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "6.exe" Then
    Local $client= "/box:6   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "7.exe" Then
    Local $client= "/box:7   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "8.exe" Then
    Local $client= "/box:8   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "9.exe" Then
    Local $client= "/box:9   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "10.exe" Then
    Local $client= "/box:10   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "11.exe" Then
    Local $client= "/box:11   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "12.exe" Then
    Local $client= "/box:12   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "13.exe" Then
    Local $client= "/box:13   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "14.exe" Then
    Local $client= "/box:14   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "15.exe" Then
    Local $client= "/box:15   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf

    If $NamePidActwin = "16.exe" Then
    Local $client= "/box:16   %USERPROFILE%\Desktop\Scripts\job.exe"
    RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)
    EndIf



    ;MsgBox(0, '', $NamePidActwin)


   Func _Findpidname($Pid)
       Local $Processlist = ProcessList()
       For $i = 1 To $Processlist[0][0]
           If $Processlist[$i][1] = $Pid Then Return $Processlist[$i][0]
       Next
   EndFunc   ;==>_Findpidname

@jchd I launched your script it pop up a window with all process, im a bit lost what next step?

Posted

you could simplify your code by doing this (untested) but you get the idea :

Local $box = Number(StringRegExp($NamePidActwin,"(\d+).",$STR_REGEXPARRAYMATCH)[0])
Local $client= "/box:" & $box & " %USERPROFILE%\Desktop\Scripts\job.exe"
RunWait(@ComSpec & ' /c "C:\Program Files\Sandboxie\Start.exe" ' & $client, "", @SW_HIDE)

 

 

Posted (edited)

Have a look at _WinAPI_GetParentProcess and _ProcessGetName.  The script will need to be compiled for it to work correctly.  

#include <Process.au3>
#include <WinAPIProc.au3>

Global $iScriptParentPID = _WinAPI_GetParentProcess(@AutoItPID)
Global $sParentProcessName = _ProcessGetName($iScriptParentPID)
MsgBox(0, "Process Name", $sParentProcessName) ;For testing.

 

Adam

Edited by AdamUL
Posted

Ah, this Win API escaped my search...

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)

Posted
56 minutes ago, AdamUL said:

Have a look at _WinAPI_GetParentProcess and _ProcessGetName.  The script will need to be compiled for it to work correctly.  

#include <Process.au3>
#include <WinAPIProc.au3>

Global $iScriptParentPID = _WinAPI_GetParentProcess(@AutoItPID)
Global $sParentProcessName = _ProcessGetName($iScriptParentPID)
MsgBox(0, "Process Name", $sParentProcessName) ;For testing.

 

Adam

Worked perfectly, thank you, thank ya all :cheer:

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.
×
×
  • Create New...