Jump to content

How to get process name to call a function


Recommended Posts

Please what am i doing wrong here.\

I want my program to call a function with the process name i write in the script is the same as the name in process list. if is the same name then it gives a message , if not then it gives a message that it is not.

 

I will compile it and save it as test.exe

 

if the process name in the script should be the name running in process list then it tells me "the name matches" if not then it tells me "the name doesnt math"

 

please any help?

#include <MsgBoxConstants.au3>
#include <Process.au3>


Local $iPid = WinGetProcess("test.exe", "")

Local $sName = _ProcessGetName($iPid)

if $sName then
MsgBox($MB_SYSTEMMODAL,"Box", "The name match the process name" )
Else
    MsgBox($MB_SYSTEMMODAL,"Box", "The name doesnt match the process name" )
endif

 

Link to comment
Share on other sites

#Include <Process.au3>
Instance_Check()

Func Instance_Check()
    Local $PROCESS_LIST = ProcessList('SomeProcess.exe')
    For $i = 1 To $PROCESS_LIST[0][0]
        ConsoleWrite($PROCESS_LIST[$i][0] & ' [' & $PROCESS_LIST[$i][1] & ']' & @CRLF)
    Next
EndFunc


Result:
SomeProcess.exe [PID]

$PROCESS_LIST[$i][0] ; This returns the process name *.exe
$PROCESS_LIST[$i][1] ; This returns the process ID

 

Example use:

#Include <Process.au3>
Instance_Check()

Func Instance_Check()
    Local $PROCESS_LIST = ProcessList('Chrome.exe')
    For $i = 1 To $PROCESS_LIST[0][0]
        ConsoleWrite($PROCESS_LIST[$i][0] & ' [' & $PROCESS_LIST[$i][1] & ']' & @CRLF)
        If $PROCESS_LIST[$i][0] = 'Chrome.exe' Then
            ExitLoop
        Else
            ContinueLoop
        Endif
    Next

    Other_Func()
EndFunc

Func Other_Func()
    ConsoleWrite('Process Found!' & @CRLF)
EndFunc


Result:

chrome.exe [54524]
Process Found!

 

Edited by FengHuangWuShen
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...