🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.databases.ms-access
Article #243

Re: Get ProcessID for given task

#243
From: Dev Ashish
Date: Thu, 22 Jul 1999 00:00
85 lines
3239 bytes
Hi Jeppe,

  Try something like this if you know the class name of theapp you're
looking for.

'************** Code Start ***************
Private Declare Function apiGetWindow Lib "user32" _
    Alias "GetWindow" _
    (ByVal hWnd As Long, _
    ByVal wCmd As Long) _
    As Long

Private Declare Function apiGetWindowThreadProcessId Lib "user32" _
    Alias "GetWindowThreadProcessId" _
    (ByVal hWnd As Long, _
    lpdwProcessID As Long) _
    As Long

Private Declare Function apiGetDesktopWindow Lib "user32" _
    Alias "GetDesktopWindow" () _
    As Long

Private Declare Function apiGetClassName Lib "user32" _
    Alias "GetClassNameA" _
    (ByVal hWnd As Long, _
    ByVal lpClassname As String, _
    ByVal nMaxCount As Long) _
    As Long

Private Declare Function apiGetWindowLong Lib "user32" _
  Alias "GetWindowLongA" _
  (ByVal hWnd As Long, _
  ByVal nIndex As Long) _
  As Long

Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Const GWL_STYLE = (-16)
Private Const WS_VISIBLE = &H10000000
Private Const MAX_LEN = 255

Function fGetProcessID(ByVal strClassName As String) As Long
Dim hWnd As Long
Dim lngStyle As Long
Dim lpdwProcessID As Long

    hWnd = apiGetWindow(apiGetDesktopWindow, GW_CHILD)
    Do While hWnd
        lngStyle = apiGetWindowLong(hWnd, GWL_STYLE)
        If (lngStyle And WS_VISIBLE) Then
            If StrComp(strClassName, fGetClassName(hWnd)) = 0 Then
                Call apiGetWindowThreadProcessId(hWnd, lpdwProcessID)
                fGetProcessID = lpdwProcessID
                Exit Function
            End If
        End If
        hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
    Loop
End Function

Private Function fGetClassName(hWnd As Long)
    Dim strBuffer As String
    Dim lngCount As Long

    strBuffer = String$(MAX_LEN - 1, 0)
    lngCount = apiGetClassName(hWnd, strBuffer, MAX_LEN)
    If lngCount > 0 Then
        fGetClassName = Left$(strBuffer, lngCount)
    End If
End Function
'************** Code End ***************

    -- Dev

DHI <jeppe_klingberg_x@bigfoot.com> wrote in message
news:MPG.1200ed9fd827fcb8989681@news.dhi.dk...
: Hi Folks,
:
: Well, it may be a bit off-topic but I need a function in my Access
: App. (properly a MFD-function) which returns the process-ID for a given
: task as shown in the Task Manager.
:
: Thanx in advance..
:
: Regards Jeppe
Technical Details
Message-ID: <7n80iq$lob$1@bgtnsc02.worldnet.att.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <MPG.1200ed9fd827fcb8989681@news.dhi.dk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fcdf9,9db5366a0bb2cc07
X-Google-Attributes: gidfcdf9,public
X-Google-Thread: ff0ac,9db5366a0bb2cc07
X-Google-Attributes: gidff0ac,public
From: "Dev Ashish" <dash10@hotmail.com>
Subject: Re: Get ProcessID for given task
Date: 1999/07/22
Message-ID: <7n80iq$lob$1@bgtnsc02.worldnet.att.net>
X-Deja-AN: 504151593
References: <MPG.1200ed9fd827fcb8989681@news.dhi.dk>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
X-Complaints-To: abuse@worldnet.att.net
X-Trace: bgtnsc02.worldnet.att.net 932677018 22283 12.78.106.243 (22 Jul 1999 20:56:58 GMT)
Organization: AT&T WorldNet Services
X-MSMail-Priority: Normal
NNTP-Posting-Date: 22 Jul 1999 20:56:58 GMT
Newsgroups: comp.databases.ms-access,dk.edb.database