哪些进程可以关闭,如何得到一个进程打开了哪些文件?

如何得到一个进程打开了哪些文件? - 故障解答 - 电脑教程网

如何得到一个进程打开了哪些文件?

日期:2006-10-02   荐:
如何得到一个进程打开了哪些文件?一个进程启动了哪些模块(dll)比较好得到,但如何得到一个进程打开了哪些文件呢?有谁清楚这个,拜托给点代码好吗?有谁知道吗?如果是自己写的程序,自己加一个变量区分?gt;>1热鏦ord这样的窗口,可以在每个窗口里放一个AnsiString File;用来标志当前打开的文件名。如果你是winxp,可用cmd方式下的openfiles.exe你可直接用WinExec或CreateProcess运行它,用 CreateProcess 还可在程序中得到结果打开的时候自己记录一下用http://www.codeguru.com/Cpp/W-P/files/fileio/article.php/c1287Deleting Locked Files里面的类void list_files_of_process(LPCTSTR process_name){//process_name: process name, Eg. notepad.exeCString deviceFileName;CString fsFilePath;CString name;CString processName;SystemHandleInformation hi;SystemProcessInformation pi;SystemProcessInformation::SYSTEM_PROCESS_INFORMATION* pPi;if ( !hi.SetFilter( _T("File"), TRUE ) ){_tprintf( _T("SystemHandleInformation::SetFilter() failed.") );return;}if ( !pi.Refresh() ){_tprintf( _T("SystemProcessInformation::Refresh() failed.") );return;}for ( POSITION pos = hi.m_HandleInfos.GetHeadPosition(); pos != NULL; ){SystemHandleInformation::SYSTEM_HANDLE& h = hi.m_HandleInfos.GetNext(pos);if ( !pi.m_ProcessInfos.Lookup( h.ProcessID, pPi ) )continue;if ( pPi == NULL )continue;SystemInfoUtils::Unicode2CString( &pPi->usName, processName );if( _tcsicmp(processName, process_name)!= 0 )continue;//NT4 Stupid thing if I query the name of a file in services.exe//Messengr service brings up a message dialog ??? :(if ( INtDll::dwNTMajorVersion == 4 && _tcsicmp( processName, _T("services.exe") ) == 0 )continue;hi.GetName( (HANDLE)h.HandleNumber, name, h.ProcessID );_tprintf("%s",(LPCTSTR)name);}}其他有用的文章http://www.codeguru.com/Cpp/W-P/system/processesmodules/article.php/c2827Examine Information on Windows NT System Level Primitiveshttp://www.codeguru.com/Cpp/W-P/files/fileinformation/article.php/c4453/FileObjectInfo - Digging into the Windows NT Internals我以前问过这个问题,你可以找找看.
标签: