>>EnumProcesses...OpenProc
>>does this sound logical...?
No. There is no documented way.
But there is an undocumented one www.sysinternals.com, HandleEx.
Main Topics
Browse All Topicsi'm interested in knowing the steps to obtaining filehandles or file descriptors for every open file on the system. i can do it in unix, from studying the fstat source...but there's not a true translation from the kvm_* calls to something in win32...anyone have any ideas?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>>EnumProcesses...OpenProc
>>does this sound logical...?
No. There is no documented way.
But there is an undocumented one www.sysinternals.com, HandleEx.
thanks nick...i'm actually doing research on a similar product that provides it's own equivalent functionality...i've been debugging through the process with a little luck, but it's ending prematurely in windasm...so i'm having to "fill in the blanks"...i'll have a look at this device driver too, to see if i can get something from it as well and let you know how it goes...thanks.
OK, here we go:
#define UNICODE
#define _UNICODE
#include <ntdll.h>
#include <tchar.h>
#include <stdio.h>
#pragma waring ( disable: 4768)
#include <list>
//...
typedef std::list<OBJECT_NAME_INFO
void AppendObjectInformation ( HANDLE hObject, obj_list* pList)
{
NTSTATUS ntStatus;
OBJECT_BASIC_INFORMATION obi;
POBJECT_TYPE_INFORMATION poti;
POBJECT_NAME_INFORMATION poni;
ULONG ul;
ZwQueryObject ( hObject,
ObjectBasicInformation,
&obi,
sizeof ( obi),
&ul
);
ul = obi.TypeInformationLength + 2;
poti = ( POBJECT_TYPE_INFORMATION) new char [ ul];
ntStatus = ZwQueryObject ( hObject,
ObjectTypeInformation,
poti,
ul,
&ul
);
if ( wcscmp ( poti->Name.Buffer, L"File"))
{
delete [] poti;
return;
}
ul = !obi.NameInformationLength
? MAX_PATH * sizeof ( WCHAR)
: obi.NameInformationLength;
poni = ( POBJECT_NAME_INFORMATION) new char [ ul];
ntStatus = ZwQueryObject ( hObject,
ObjectNameInformation,
poni,
ul,
&ul
);
pList->push_back ( poni);
delete [] poti;
}
void GetOpenFileList ( DWORD dwPID, obj_list* pList)
{
NTSTATUS ntStatus;
HANDLE hObject;
HANDLE hProcess;
PSYSTEM_HANDLE_INFORMATION
ULONG ul = 0x1000;
PULONG pul = new ULONG [ ul];
hProcess = OpenProcess ( PROCESS_DUP_HANDLE, FALSE, dwPID);
while ( STATUS_INFO_LENGTH_MISMATC
pul,
ul * sizeof ( ULONG),
0
)
) delete [] pul, pul = new ULONG [ ul *= 2];
pshi = ( PSYSTEM_HANDLE_INFORMATION
for ( ULONG i = 0; i < *pul; i++)
{
if ( pshi [ i].ProcessId != dwPID) continue;
hObject = NULL;
ZwDuplicateObject ( hProcess,
( HANDLE) pshi [ i].Handle,
NtCurrentProcess (),
&hObject,
0,
0,
DUPLICATE_SAME_ATTRIBUTES
);
if ( hObject)
AppendObjectInformation ( hObject, pList);
}
delete [] pul;
}
void PrintList ( obj_list* _p)
{
obj_list::iterator _i;
for ( _i = _p->begin ();
_i != _p->end ();
_i++
)
{
wprintf ( L"%s\n", (*_i)->Name.Buffer);
}
}
int wmain ( int wargc,
wchar_t** wargv
)
{
DWORD dwPID;
wchar_t* pwc;
obj_list _list;
if ( 2 != wargc)
return ( -1);
dwPID = wcstol ( *( wargv + 1), &pwc, 10);
GetOpenFileList ( dwPID, &_list);
PrintList ( &_list);
return ( 0);
}
The executable itself is on the way via email. If it suits your needs, the project will follow ;-)
What you are seeing is the whole project - the only thing missing is 'ntdll.h':
#include <windows.h>
namespace NT
{
extern "C"
{
#pragma warning ( disable: 4005)
#include <basetsd.h>
#include <ntddk.h>
#pragma warning ( default: 4005)
}
}
using NT::NTSTATUS;
using NT::UNICODE_STRING;
using NT::PUNICODE_STRING;
using NT::OBJECT_ATTRIBUTES;
Hi.
I was unable to compile it. I run the BLD command from the DDK (2600) cmd line (with TARGET=PROGRAM) and it returns with 44 errors
Like:
e:\winddk\inc\ddk\wxp\ntdd
or
main.cpp(21) : error C2065: 'ZwQueryObject' : undeclared identifier.
Would you, please, send the project or tell me what am I doing wrong ?
thanks again
Business Accounts
Answer for Membership
by: Droby10Posted on 2001-04-22 at 19:03:11ID: 6025630
i think i'm on the right track following EnumProcesses...OpenProces sToken...O penProcess ...and somehow ending up at GetStdHandle....does this sound logical...? if so what are the parts that i'm missing...?
thanks.