473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Getting the process from the Application

Hi,
If I have the Application Handle (of say Notepad), how can i get the thread/process name i.e. Notepad.exe or other information?
I tried to use this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_process.asp
But unfortunately, the handle property does not contain the application handle, but the process's handle.

Thanks in Advance!

Regards,
Prakhar Birla
Nov 21 '06 #1
1 1288
Thank you for the trouble people, but i figured it out for myself! Here it is, if someone else needs it
Expand|Select|Wrap|Line Numbers
  1. Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long
  2.  
  3. Function getPIDfromHandle(target_hwnd As Long) As Long
  4. Dim test_pid As Long
  5. Dim test_threadid As Long
  6. test_hwnd = final_hwnd
  7. test_threadid = GetWindowThreadProcessId(target_hwnd, test_pid)
  8. getPIDfromHandle = test_pid
  9. End Function
  10.  
  11. Function getPathfromPID(PID As Long) As String
  12. Dim strComputer As String
  13. strComputer = "."
  14. Set objWMIService = GetObject("winmgmts:" _
  15.     & "{impersonationLevel=impersonate}!\\" _
  16.     & strComputer & "\root\cimv2")
  17.  
  18. Set colProcesses = objWMIService.ExecQuery( _
  19.     "select * from win32_process")
  20. getPathfromPID = Null
  21. For Each objProcess In colProcesses
  22.    If objProcess.ProcessID = PID Then
  23.    getPathfromPID = objProcess.ExecutablePath
  24.    Exit For
  25.    End If
  26. Next
  27. End Function
Nov 21 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
2
by: David Hearn | last post by:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Description: An unhandled exception occurred during the execution of the current...
4
by: TS | last post by:
in my web project's bin folder, the dll, that comes from a project reference of a class library in same solution, can't be deleted. it says it has a sharing violation. i also cannot delete the...
2
by: MSK | last post by:
Hi, Continued to my earlier post regaring "Breakpoints are not getting hit" , I have comeup with more input this time.. Kindly give me some idea. I am a newbie to .NET, recently I installed...
1
by: Nick | last post by:
Hi, I have following question: Two applications ( exe) work on the same computer in the same AppDomain. For example: First is called " agent ", second is called "Client". "Agent" load data from...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
4
by: Daniel | last post by:
is there some per-process-limit on memory in .net processes? is there any way to increase it? i keep getting System.OutOfMemoryException when my box has 8 gigs of unused memory.
2
by: Tim | last post by:
Hey guys, I tried to get a process handle with the following code snippet: 00 Process processes = Process.GetProcesses(); 01 if (null != processes && processes.Length 0) 02 { 03 foreach...
2
by: shorti | last post by:
Hello, I am running DB2 V8.2 on AIX. I am looking for a way to get the memory size of a specific db2 agent. I have found the db2mtrk tool that gives me a list of all the applications and heap...
1
by: viswanathtvs | last post by:
java.util.NoSuchElementException javax.faces.el.EvaluationException: java.util.NoSuchElementException at...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.