|
-
Oct 2nd, 2002, 08:21 AM
#1
Thread Starter
New Member
Getting the Path a program was launched from
I've been able to get the hwnd for the active window. I have also been able to get what the exe is of the program. Both of these I found out how to do from these forums.
One thing I haven't found is if it is possible to find the path a program was launched from if you have the hwnd?
Thanks for any help, and soz in advance if this has been answered before, but I couldn't fin dit
-
Oct 2nd, 2002, 10:30 PM
#2
Fanatic Member
If you used something like GetWindowThreadProcessID() to get the PID of the process that made the window, and then get info about the exe that way, the path should be along with the exe name itself. I answered a question a while back for someone about this, and one of the things that eventually came out of it was the full path and name of the exe that the process is running, so you may want to look at it.
http://www.vbforums.com/showthread.p...hreadid=198867 (go about halfway down and take a look at GetEXEName())
If that isn't the path you're talking about, just ignore these babblings. I think you can get the actual command line an exe was launched with in some manner though, assuming the path in question was a parameter. If it was from the "Launch in:" part of a shortcut's properties, I'm not sure how to get that, or even if you can.
Last edited by Kaverin; Oct 2nd, 2002 at 10:34 PM.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Oct 3rd, 2002, 04:09 AM
#3
Thread Starter
New Member
Thanks for the reply, one of my mates got it going.
This is the code from the module he made if anyone is interested
Code:
Public Const TH32CS_SNAPMODULE As Long = 8&
Public Const MAX_PATH As Long = 260
Public Type MODULEENTRY32
dwSize As Long
th32ModuleID As Long
th32ProcessID As Long
GlblcntUsage As Long
ProccntUsage As Long
modBaseAddr As Long
modBaseSize As Long
hModule As Long
szModule As String * 256
szExePath As String * 260
End Type
Public Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hWnd As Long, lpdwProcessId As Long) As Long
Public Declare Function CreateToolhelpSnapshot Lib "kernel32" _
Alias "CreateToolhelp32Snapshot" (ByVal lFlgas As Long, ByVal _
lProcessID As Long) As Long
Public Declare Function Module32First Lib "kernel32" (ByVal hSnapshot As _
Long, lppe As Any) As Long
Public Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Public Function GetExeFromHandle(hWnd As Long) As String
Dim threadID As Long, processID As Long, hSnapshot As Long
Dim uProcess As MODULEENTRY32, rProcessFound As Long
Dim i As Integer, szExename As String
szExename = ""
' Get ID for window thread
threadID = GetWindowThreadProcessId(hWnd, processID)
' Check if valid
If threadID = 0 Or processID = 0 Then Exit Function
' Create snapshot of current processes
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPMODULE, processID)
' Check if snapshot is valid
If hSnapshot = -1 Then Exit Function
'Initialize uProcess with correct size
uProcess.dwSize = Len(uProcess)
'Start looping through processes
rProcessFound = Module32First(hSnapshot, uProcess)
If rProcessFound Then
i = InStr(1, uProcess.szExePath, Chr(0))
If i > 0 Then szExename = Left$(uProcess.szExePath, i - 1)
End If
Call CloseHandle(hSnapshot)
GetExeFromHandle = szExename
End Function
-
Oct 24th, 2002, 12:04 AM
#4
Hyperactive Member
good code - using
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|