From: Kevin Provance on

"Ed" <nospam(a)hotmail.com> wrote in message
news:ckus261kfmsqhf9aue22houl3m495egdsa(a)4ax.com...
: I've used the code below in XP, Vista and Win7 32-bit flavors to get the
full path to a running executable by their
: Process ID, but under Win7-64-bit it only returns the file path to 32-bit
files, if the PID is from a 64-bit exe it
: returns nothing! Does anyone know of a working VB6 solution for this
problem?
:
: Thanks for looking,
: Ed
: ---
:
: Private Function ExePathFromProcID(idProc As Long) As String
:
: Dim S As String
: Dim c As Long
: Dim hModule As Long
: Dim ProcHndl As Long
:
: S = String$(MAX_PATH, 0)
: ProcHndl = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0,
idProc)
:
: If ProcHndl Then
: If EnumProcessModules(ProcHndl, hModule, 4, c) <> 0 Then c =
GetModuleFileNameEx(ProcHndl, hModule, S, MAX_PATH)
: If c Then ExePathFromProcID = Left$(S, c)
: CloseHandle ProcHndl
: End If
:
: End Function

Since VB executables run in the 32 bit address spaces, I'm thinking not.
That said, I'm not sure if some kind of WOW APIs exist to do such a thing.
I would Google those terms and see what turns up.

From: Nobody on
This was discussed few months ago. See this thread:

Win32 in an x64 world:
http://groups.google.com/group/microsoft.public.vb.winapi/browse_thread/thread/6cf315a8c20976b9/3c1b5e875714dc2d



From: Karl E. Peterson on
Ed formulated on Sunday :
> On Sun, 04 Jul 2010 05:58:32 -0500, Ed <nospam(a)hotmail.com> wrote:
>
>> On Sat, 3 Jul 2010 00:09:19 -0400, "Nobody" <nobody(a)nobody.com> wrote:
>>
>>> This was discussed few months ago. See this thread:
>>>
>>> Win32 in an x64 world:
>>> http://groups.google.com/group/microsoft.public.vb.winapi/browse_thread/thread/6cf315a8c20976b9/3c1b5e875714dc2d
>
> Thanks Nobody, I spoke too soon, after looking at Karl's snippet again I got
> it. :) Thanks again!

So did you end up needing to elevate to Debug privs?

I'm not sure a link was in that thread, but I did pretty much wrap that
up here: http://vb.mvps.org/samples/Uptime

For the sake of the thread, pass True to this function to elevate, and
False to slide back to normal...

Private Function DebugPrivs(ByVal Enable As Boolean) As Boolean
Dim hProcess As Long
Dim DesiredAccess As Long
Dim hToken As Long
Dim tkp As TOKEN_PRIVILEGES
Dim nRet As Long

' Cache a copy of priviliges as we found them.
Static bup As TOKEN_PRIVILEGES

' Get psuedohandle to current process.
hProcess = GetCurrentProcess()
' Ask for handle to query and adjust process tokens.
DesiredAccess = TOKEN_QUERY Or TOKEN_ADJUST_PRIVILEGES
If OpenProcessToken(hProcess, DesiredAccess, hToken) Then
' Get LUID for backup privilege name.
If LookupPrivilegeValue(vbNullString, SE_DEBUG_NAME, tkp.LUID)
Then
If Enable Then
' Enable the debug priviledge.
tkp.PrivilegeCount = 1
tkp.Attributes = SE_PRIVILEGE_ENABLED
If AdjustTokenPrivileges(hToken, False, tkp, Len(bup),
bup, nRet) Then
DebugPrivs = True
End If
Else
' Restore prior debug privilege setting.
If AdjustTokenPrivileges(hToken, False, bup, 0&, ByVal
0&, nRet) Then
DebugPrivs = True
End If
End If
End If
' Clean up token handle.
Call CloseHandle(hToken)
End If
End Function

(Indented to highlight wordwrap.)

--
..NET: It's About Trust!
http://vfred.mvps.org


From: Karl E. Peterson on
Ed brought next idea :
> On Tue, 06 Jul 2010 16:40:35 -0700, Karl E. Peterson <karl(a)exmvps.org> wrote:
>
>> So did you end up needing to elevate to Debug privs?
>>
>> I'm not sure a link was in that thread, but I did pretty much wrap that
>> up here: http://vb.mvps.org/samples/Uptime
>
> I guess so, my test app already sets debug privs.
>
> btw, In your Uptime sample, vb says CProcessTimes.cls not found, was
> CProcessInfo.cls supposed to be renamed?

Yikes! Yeah, I did recently update *and* rename it, to more accurately
reflect what it did. And, unfortunately, I didn't properly update the
ZIP. <groan> Just did a "freshen" which only went after the old
filename. Dang!!!

I just uploaded the right one. Please grab it to make sense of what I
posted above. It's all there this time.

So sorry...

--
..NET: It's About Trust!
http://vfred.mvps.org


From: Kevin Provance on

"Karl E. Peterson" <karl(a)exmvps.org> wrote in message
news:i1555i$8nv$1(a)news.eternal-september.org...
: Yikes! Yeah, I did recently update *and* rename it, to more accurately
: reflect what it did. And, unfortunately, I didn't properly update the
: ZIP. <groan> Just did a "freshen" which only went after the old
: filename. Dang!!!
:
: I just uploaded the right one. Please grab it to make sense of what I
: posted above. It's all there this time.
:
: So sorry...
:
: --
: .NET: It's About Trust!
: http://vfred.mvps.org

We're all entitled to the occasional slip up. Considering what you've given
to the community, I don't think anyone is going to hold you're feet over the
fire. This time. <g>