vbscript: how can I use the process id to get a windows handle

Posted on 2011-10-27
Last Modified: 2012-05-12
I can capture all the process ids for a client under test, but I currently at a loss on how to convert those ids into window handles.

Process Id Code
Function ProcessId
   'capture the hwnd  from all windows with a certain caption
set objService = getobject("winmgmts:")
		For each Process in objService.InstancesOf("Win32_process")   
			If  Process.Name = "FronTIER.exe" Then
						ret = msgbox(Process.processid, vbOkCancel)
If ret = vbCancel Then
							ExitTest micWarning
						End If
			End If

End Function

Open in new window

Question by:ART_Mac03
    LVL 13

    Expert Comment

    From command prompt:

    >tasklist | findstr <PID>
    LVL 15

    Accepted Solution


    ret = msgbox(Process.processid, vbOkCancel)


    ret = msgbox("ProcessID:" & Process.processid & "; Handle:" " & Process.handle, vbOkCancel)

    Author Comment

    let me try this. I do not know I could not think of this simple solution.

    I need to my code simple due to my users; your solution can be what they would like.

    Author Comment

    typo: I do not know why I did not think of this solution.

    Author Closing Comment

    The solution was helpful especially since the info. displayed to my user community was direct and non-complex.
    I eventually found a different way to solve my org. problem with using Process IDs to determine Window handles. I am using the test tool QTP to capture the windows object data based on the Swfname of the application or the object name of a feature in the app.  I pass the object name based on the process ID/name of the process.

    Author Comment

    thanks for both solutions.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Article by: Leon
    Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
    Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
    The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
    The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now