Process( ).Handles empty in Vista 64-bit

delphi package - easy access to kernel objects etc.
Post Reply
brian
Posts: 38
Joined: Fri Feb 29, 2008 11:12 am

Process( ).Handles empty in Vista 64-bit

Post by brian »

It seems this doesn't work at all Vista-64 bit, process handles are empty, itemcount 0.
madshi
Site Admin
Posts: 10339
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Sorry for the late reply.

The Windows API used for enumerating handles doesn't work when being called from within a 32bit process in a 64bit OS, sadly. You'd need a 64bit process to get this information. Shame on Microsoft... :cry:
brian
Posts: 38
Joined: Fri Feb 29, 2008 11:12 am

Post by brian »

Ahh I see. Shame on borland/cg for not having a 64-bit compiler yet.
brian
Posts: 38
Joined: Fri Feb 29, 2008 11:12 am

Post by brian »

After further testing, this seems to be working in Windows 7-64 bit, but only if both processes are running with the same user privileges. For example, you run your delphi app normally, and try to get the handles for another (32-bit) app that you ran as admin, it won't work. If both are are under normal privs or both as admin, it works. Think of any workaround for this?

example code


Var a: integer;
b: string;
begin

with Process('whatever.exe').Handles do
for a := 0 to ItemCount - 1 do
with Items[a] do
begin
Application.ProcessMessages;
if not IsValid then Continue;
if not (ObjType in [otFile, otFileMapping]) then Continue;
b := KernelObj.ObjName;
if b = '' then Continue;
memo1.lines.add(b);
end;
madshi
Site Admin
Posts: 10339
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I'm surprised that it works at all, but I won't complain about that... :wink:

I guess the "proper" solution to the privileges problem is to either install your app as a service, or to add a manifest to your exe file which tells Windows that you need admin rights.
brian
Posts: 38
Joined: Fri Feb 29, 2008 11:12 am

Post by brian »

Well, the thing is, if your app is running as admin, and the other app isn't, it still doesn't work, both have to be running on the same level :O
madshi
Site Admin
Posts: 10339
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

That sounds very weird to me. Honestly, I have no idea why it behaves this way! Maybe MS has hardcoded the underlying APIs to work this way? Don't really know... :?
Sugar70
Posts: 2
Joined: Wed Dec 22, 2010 12:47 am

Re: Process( ).Handles empty in Vista 64-bit

Post by Sugar70 »

You'd need a 64bit process to get this information. Shame on Microsoft... : :crazy: :crazy:
brian
Posts: 38
Joined: Fri Feb 29, 2008 11:12 am

Re: Process( ).Handles empty in Vista 64-bit

Post by brian »

It does actually work with a 32-bit process, if both your application and the one retrieving the info about, are running on the same privilege level (user/user or admin/admin).
Post Reply