Jump to content

WinGetProcessName


therks
 Share

Recommended Posts

I'm not as hot over this one as I am over my other UDF posted today. This one didn't really require much work, but I found it handy for a script I've been working on. Should be fairly straightforward. Instead of just returning the PID for a window, this returns the process's name (and it also returns the PID in @extended).

;===============================================================================
;
; Description:      _WinGetProcessName - Retrieves the name of the Process associated with a window.
; Syntax:           _WinGetProcessName ( $s_Title [, $s_Text ] )
; Parameter(s):     $s_Title - Title of the window to read.
;                   $s_Text [optional] - Text of the window to read.
; Return Value(s):  Success: Returns the name of the Process the window belongs to,
;                   and sets @extended to the Process ID
;                   Failure: Returns False, and sets @error to 1
; Author(s):        Saunders (rksaunders@gmail.com)
;
;===============================================================================

Func _WinGetProcessName($s_Title, $s_Text = '')
    Local $i_PID, $a_ProcList
    $i_PID = WinGetProcess($s_Title, $s_Text)
    If $i_PID <> -1 Then
        $a_ProcList = ProcessList()
        For $i_For = 1 to $a_ProcList[0][0]
            If $a_ProcList[$i_For][1] = $i_PID Then
                SetExtended($i_PID)
                Return $a_ProcList[$i_For][0]
            EndIf
        Next
    EndIf
    SetError(1)
    Return False
EndFunc
Link to comment
Share on other sites

I'm not as hot over this one as I am over my other UDF posted today. This one didn't really require much work, but I found it handy for a script I've been working on. Should be fairly straightforward. Instead of just returning the PID for a window, this returns the process's name (and it also returns the PID in @extended).

This will come in handy to indentify a process, but would be nice to have a _KillWinProcess($i_PID) or Terminate function. Do you have anything like this in your tool box? :)

Cheers.. :evil:

Link to comment
Share on other sites

Uhm, wouldn't that be ProcessClose()? Or did you want one where you could specify window title, and it would close the process? That shouldn't be hard...

Without testing.. I think this will work:

Func _WinProcessClose($s_Title, $s_Text = '')
    Local $i_PID, $a_ProcList
    $i_PID = WinGetProcess($s_Title, $s_Text)
    If $i_PID <> -1 Then
        $a_ProcList = ProcessList()
        For $i_For = 1 to $a_ProcList[0][0]
            If $a_ProcList[$i_For][1] = $i_PID Then
                Return ProcessClose($i_PID)
            EndIf
        Next
    EndIf
    SetError(1)
    Return False
EndFunc

After some quick testing, seems it works.

Edited by Saunders
Link to comment
Share on other sites

Uhm, wouldn't that be ProcessClose()? Or did you want one where you could specify window title, and it would close the process? That shouldn't be hard...

Without testing.. I think this will work:

Func _WinProcessClose($s_Title, $s_Text = '')
    Local $i_PID, $a_ProcList
    $i_PID = WinGetProcess($s_Title, $s_Text)
    If $i_PID <> -1 Then
        $a_ProcList = ProcessList()
        For $i_For = 1 to $a_ProcList[0][0]
            If $a_ProcList[$i_For][1] = $i_PID Then
                Return ProcessClose($i_PID)
            EndIf
        Next
    EndIf
    SetError(1)
    Return False
EndFunc

After some quick testing, seems it works.

<{POST_SNAPBACK}>

I am looking to close a process that may not have a window open, which just might be a ProcessClose() function. I would like to shortcut going to the Windows TaskManager then closing the process that I know has crashed but the {.EXE} is still running for some reason. It is a shortcut-lazy thing.. :)

I will give your code a try, Thanks!! :D

Cheers.. :evil:

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...