Sign in to follow this  
Followers 0
cypher175

check if a specific .exe - process is running or not from a specific location..?

7 posts in this topic

#1 ·  Posted (edited)

How could I code an AutoIt app to check if a specific .exe - process is running or not from a specific location and if its not found running then have it get executed..

like:

If D:\desktop\notepad.exe is not found running then execute D:\desktop\notepad.exe

and have this autoit app run on a infinite loop checking every 10 Seconds to see if D:\desktop\notepad.exe is found running or not

so it can execute it if its not found running..

Edited by cypher175

Share this post


Link to post
Share on other sites



You can simply check if a program is running ,

Ex : ProcessExist(), WinExist()

While 1
if ProcessExist("Notepad","") then
msgbox(64,"","Found")
endif
sleep(10000)
Wend

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites

How could I code an AutoIt app to check if a specific .exe - process is running or not from a specific location and if its not found running then have it get executed..

like:

If D:\desktop\notepad.exe is not found running then execute D:\desktop\notepad.exe

and have this autoit app run on a infinite loop checking every 10 Seconds to see if D:\desktop\notepad.exe is found running or not

so it can execute it if its not found running..

If the process can be running more than once (like notepad).

ProcessList()

Enum through the list and check their path with _ProcessGetPath() and an If/Then conditional statement... ie:

Local $b_true_path = False
Local $a_pl = ProcessList("notepad.exe")
For $i = 1 To $a_pl[0][0]
    If _ProcessGetPath($a_pl[$i][1]) = "Location" Then
        $b_true_path = True
        ExitLoop
    EndIf
Next

If Not $b_true_Path Then Run("Location\exe")
Find a _ProcessGetPath here: http://www.autoitscript.com/forum/index.ph...st&p=532206

Or here:

http://www.autoitscript.com/forum/index.ph...ssGetPath\


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

ok im tring that code with 2 of the same calc.exe files. i just copied one over to a new directory at c:\calc\calc.exe

i executed c:\windows\system32\calc.exe first and left it open while i tested your autoit code you provided me.

but nothing happen though.. C:\calc\calc.exe didn't even get executed...??

and I also get this error when i check the "SyntaxCheck Prod"

(4,36) : ERROR: _ProcessGetPath(): undefined function.

If _ProcessGetPath($a_pl[$i][1])

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

My AutoIt Code..

Local $b_true_path = False
Local $a_pl = ProcessList("calc.exe")
For $i = 1 To $a_pl[0][0]
    If _ProcessGetPath($a_pl[$i][1]) = "C:\calc" Then
        $b_true_path = True
        ExitLoop
    EndIf
Next

If Not $b_true_Path Then Run("C:\calc\calc.exe")

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

ok im tring that code with 2 of the same calc.exe files. i just copied one over to a new directory at c:\calc\calc.exe

i executed c:\windows\system32\calc.exe first and left it open while i tested your autoit code you provided me.

but nothing happen though.. C:\calc\calc.exe didn't even get executed...??

and I also get this error when i check the "SyntaxCheck Prod"

(4,36) : ERROR: _ProcessGetPath(): undefined function.

If _ProcessGetPath($a_pl[$i][1])

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

My AutoIt Code..

Local $b_true_path = False
Local $a_pl = ProcessList("calc.exe")
For $i = 1 To $a_pl[0][0]
    If _ProcessGetPath($a_pl[$i][1]) = "C:\calc" Then
        $b_true_path = True
        ExitLoop
    EndIf
Next

If Not $b_true_Path Then Run("C:\calc\calc.exe")
You have = "C:\calc" ... probably should be: "C:\calc\calc.exe" or @SystemDir & "\Calc.exe" ?

Edit:

Ahh... didn't even look at the error.

I sent you to the link to get the _ProcessGetPath() function, did you forget to put that in there?

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

are you talking about this..??

$sAutoItProcList = _GetAutoItProcList()

ConsoleWrite($sAutoItProcList)

Func _GetAutoItProcList()
    Local $aProcList = ProcessList()
    Local $sRet_List = "", $sProc_Path = ""
   
    For $i = 1 To UBound($aProcList)-1
        $sProc_Path = _ProcessGetPath($aProcList[$i][1])
       
        If StringInStr(FileGetVersion($sProc_Path, "CompiledScript"), "AutoIt") Then $sRet_List &= $aProcList[$i][0] & @CRLF
    Next
   
    Return StringStripWS($sRet_List, 3)
EndFunc

Func _ProcessGetPath($vProcess)
    Local $iPID = ProcessExists($vProcess)
    If Not $iPID Then Return SetError(1, 0, -1)
   
    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If Not IsArray($aProc) Or Not $aProc[0] Then Return SetError(2, 0, -1)
   
    Local $vStruct = DllStructCreate('int[1024]')
   
    Local $hPsapi_Dll = DllOpen('Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then Return SetError(3, 0, '')
   
    DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _
        'hwnd', $aProc[0], _
        'ptr', DllStructGetPtr($vStruct), _
        'int', DllStructGetSize($vStruct), _
        'int_ptr', 0)
    Local $aRet = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _
        'hwnd', $aProc[0], _
        'int', DllStructGetData($vStruct, 1), _
        'str', '', _
        'int', 2048)
   
    DllClose($hPsapi_Dll)
   
    If Not IsArray($aRet) Or StringLen($aRet[3]) = 0 Then Return SetError(4, 0, '')
    Return $aRet[3]
EndFunc

Share this post


Link to post
Share on other sites

This runs fine:

Local $b_true_path = False
Local $a_pl = ProcessList("calc.exe")
For $i = 1 To $a_pl[0][0]
    If _ProcessGetPath($a_pl[$i][1]) = @DesktopDir & "\calc.exe" Then
        $b_true_path = True
        ExitLoop
    EndIf
Next

If Not $b_true_Path Then Run('"' & @DesktopDir & "\calc.exe" & '"')

Func _ProcessGetPath($vProcess)
    Local $iPID = ProcessExists($vProcess)
    If Not $iPID Then Return SetError(1, 0, -1)
   
    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If Not IsArray($aProc) Or Not $aProc[0] Then Return SetError(2, 0, -1)
   
    Local $vStruct = DllStructCreate('int[1024]')
   
    Local $hPsapi_Dll = DllOpen('Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then Return SetError(3, 0, '')
   
    DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _
        'hwnd', $aProc[0], _
        'ptr', DllStructGetPtr($vStruct), _
        'int', DllStructGetSize($vStruct), _
        'ptr', 0)
    Local $aRet = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _
        'hwnd', $aProc[0], _
        'int', DllStructGetData($vStruct, 1), _
        'str', '', _
        'int', 2048)
   
    DllClose($hPsapi_Dll)
   
    If Not IsArray($aRet) Or StringLen($aRet[3]) = 0 Then Return SetError(4, 0, '')
    Return $aRet[3]
EndFunc
(I put the function I sent you to there above, you should be able to copy and paste it... I copied calc.exe to my desktop ran the one from the system directory and it opened the one from my desktop as it should)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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