本文整理汇总了C++中GetModuleFileNameEx函数的典型用法代码示例。如果您正苦于以下问题:C++ GetModuleFileNameEx函数的具体用法?C++ GetModuleFileNameEx怎么用?C++ GetModuleFileNameEx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetModuleFileNameEx函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ASSERT
void CExceptionHandler::Register()
{
// (( scope ))
{
ASSERT(g_lpExceptionHandler == NULL);
// Build our required extra information.
g_szExtraInformation = GetVersionInformation();
if (g_szExtraInformation == NULL)
{
goto __failed;
}
// Find the path to create the dump files in and ensure it exists.
wstring szCrashDumpPath(GetDirname(GetModuleFileNameEx()) + L"\\" + CRASH_DUMP_PATH);
SetEnvironmentVariable(L"MOZ_CRASHREPORTER_DATA_DIRECTORY", szCrashDumpPath.c_str());
DWORD dwAttr = GetFileAttributes(szCrashDumpPath.c_str());
if (dwAttr == INVALID_FILE_ATTRIBUTES)
{
BOOL fResult = CreateDirectory(szCrashDumpPath.c_str(), NULL);
if (!fResult)
{
goto __failed;
}
}
// Set the module name as the first restart parameter so the crash
// reporter displays the restart button.
SetEnvironmentVariable(L"MOZ_CRASHREPORTER_RESTART_ARG_0", GetModuleFileNameEx().c_str());
// Create the exception handler.
g_lpExceptionHandler = new google_breakpad::ExceptionHandler(
GetDirname(GetModuleFileNameEx()).c_str(),
NULL,
MinidumpCallback,
NULL,
google_breakpad::ExceptionHandler::HANDLER_ALL
);
return;
}
__failed:
if (g_szExtraInformation != NULL)
{
free(g_szExtraInformation);
g_szExtraInformation = NULL;
}
}
开发者ID:pvginkel,项目名称:wave-notify,代码行数:59,代码来源:CExceptionHandler.cpp
示例2: FindInjectedModule
bool FindInjectedModule(DWORD processID)
{
HMODULE hMods[1024];
HANDLE hProcess;
DWORD cbNeeded;
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID);
if (hProcess == NULL)
return false;
if(EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
{
for (unsigned int i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)
{
TCHAR szModName[MAX_PATH];
if (GetModuleFileNameEx(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR))) {
char buf[MAX_PATH];
WideCharToMultiByte(CP_ACP, 0, szModName, -1, buf, MAX_PATH, "?", NULL);
string s(buf);
if (s.compare(s.length() - 6, 6, "BH.dll") == 0) {
return true;
}
}
}
}
CloseHandle(hProcess);
return false;
}
开发者ID:CodeBlueDev,项目名称:slashdiablo-maphack,代码行数:28,代码来源:cInjector.cpp
示例3: ClearUdpProcessDict
int ProcessMap::BuildUdpProcDict()
{
//清空processtcpdict
ClearUdpProcessDict();
portdict.clear();
//构建tcpportdict
MIB_UDPTABLE_OWNER_PID udptable;
udptable.dwNumEntries = sizeof(udptable)/sizeof(udptable.table[0]);
DWORD udptablesize = sizeof(udptable);
if(GetExtendedUdpTable((void *)&udptable, &udptablesize, FALSE, AF_INET, UDP_TABLE_OWNER_PID, 0) == NO_ERROR)
{
for(unsigned int i =0 ; i< udptable.dwNumEntries; i++)
{
int port = ntohs((unsigned short)udptable.table[i].dwLocalPort);
int pid = udptable.table[i].dwOwningPid;
portdict.insert(pair<int ,int>(port,pid));
}
}
//构建UdpProcessDict
// Take a snapshot
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 p;
p.dwSize = sizeof(PROCESSENTRY32);
// Traverse Process List
for(BOOL ret = Process32First(hSnapShot, &p); ret != 0; ret = Process32Next(hSnapShot, &p))
{
// Get pid and file name
int pid = p.th32ProcessID;
for(portdictit=portdict.begin();portdictit!=portdict.end();portdictit++)
{
if(portdictit->second == pid)
{
ProcessNode *processnode = new ProcessNode;
processnode->pid = pid;
processnode->processname = TCHARTochar(p.szExeFile);
// Get full path (if possible)
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
if (hProcess == 0)
{
processnode->processpath = NULL;
}
else
{
TCHAR fullPath[MAX_PATH];
if (GetModuleFileNameEx(hProcess, 0, fullPath, MAX_PATH) > 0) // Success
{
processnode->processpath = TCHARTochar(fullPath);
}
else
processnode->processpath = NULL;
}
CloseHandle(hProcess);
udpprocessdict.insert(pair<int,ProcessNode*>(portdictit->first,processnode));
}
}
}
CloseHandle(hSnapShot);
UpdateUnknowUdpportdict();
return 0;
}
开发者ID:Yight,项目名称:InfoSecurity,代码行数:60,代码来源:ProcessMap.cpp
示例4: fileName
CProfilingInfo::~CProfilingInfo(void)
{
if (!records.empty())
{
// write profile to file
TCHAR buffer [MAX_PATH] = {0};
if (GetModuleFileNameEx(GetCurrentProcess(), nullptr, buffer, _countof(buffer)) > 0)
try
{
std::wstring fileName (buffer);
fileName += L".profile";
std::string report = GetInstance()->GetReport();
CFile file (fileName.c_str(), CFile::modeCreate | CFile::modeWrite );
file.Write (report.c_str(), (UINT)report.size());
}
catch (...)
{
// ignore all file errors etc.
}
// free data
for (size_t i = 0; i < records.size(); ++i)
delete records[i];
}
}
开发者ID:YueLinHo,项目名称:TortoiseGit,代码行数:30,代码来源:ProfilingInfo.cpp
示例5: OSGetLoadedModuleList
BOOL STDCALL OSGetLoadedModuleList(HANDLE hProcess, StringList &ModuleList)
{
HMODULE hMods[1024];
DWORD count;
if (EnumProcessModulesEx(hProcess, hMods, sizeof(hMods), &count, LIST_MODULES_ALL))
{
for (UINT i=0; i<(count / sizeof(HMODULE)); i++)
{
TCHAR szFileName[MAX_PATH];
if (GetModuleFileNameEx(hProcess, hMods[i], szFileName, _countof(szFileName)-1))
{
TCHAR *p;
p = srchr(szFileName, '\\');
if (p)
{
*p = 0;
p++;
}
slwr (p);
ModuleList << p;
}
}
}
else
return 0;
return 1;
}
开发者ID:tks2103,项目名称:OBS,代码行数:31,代码来源:XT_Windows.cpp
示例6: find_process
DWORD find_process( char *pattern )
{
DWORD aProcesses[1024], cbNeeded, cProcesses, mcbNeeded;
unsigned int i;
HMODULE hMods[1024];
HANDLE hProcess;
char szModName[MAX_PATH];
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) {
deb("failed enumprocesses: %s", strerror(NULL));
return NULL;
}
cProcesses = cbNeeded / sizeof(DWORD);
for ( i = 0; i < cProcesses; i++ ) {
hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, aProcesses[i] );
if (NULL == hProcess || !EnumProcessModules(hProcess, hMods, sizeof(hMods), &mcbNeeded))
continue;
if ( GetModuleFileNameEx( hProcess, hMods[0], szModName, sizeof(szModName))) {
_strlwr(szModName);
if(strstr(szModName, pattern)) {
deb("found %s: %s (0x%08X)\n", pattern, szModName, hMods[0] );
return aProcesses[i];
}
}
CloseHandle( hProcess );
}
return NULL;
}
开发者ID:kilitary,项目名称:ss,代码行数:35,代码来源:processes.cpp
示例7: DllMain
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
{
if(reason == DLL_PROCESS_ATTACH)
{
HANDLE hproc = GetCurrentProcess();
GetModuleFileNameEx(hproc, 0, g_file_proc, sizeof(g_file_proc));
CloseHandle(hproc);
int n = GetModuleFileName(hinst, g_file_log, sizeof(g_file_log));
while(g_file_log[n] != '\\') n--;
#if defined(WIN64)
strcpy_s(g_file_log + n, sizeof(g_file_log) - n, "\\snapit_x64.log");
#else
strcpy_s(g_file_log + n, sizeof(g_file_log) - n, "\\snapit_x32.log");
#endif
_log_("attach -> %s", g_file_proc);
WMU_SNAPIT_UNINSTALL = RegisterWindowMessage(g_message_name);
g_hinst = hinst;
DisableThreadLibraryCalls(hinst);
}
if(reason == DLL_PROCESS_DETACH)
{
_log_("detach -> %s", g_file_proc);
}
return TRUE;
} // DllMain
开发者ID:akozlins,项目名称:snapit,代码行数:31,代码来源:hook.cpp
示例8: PrintProcessNameAndID
void PrintProcessNameAndID( DWORD processID )
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
TCHAR szFilename[MAX_PATH] = TEXT("<unknown>");
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID);
if (hProcess != NULL)
{
HMODULE hModule;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hModule, sizeof(hModule), &cbNeeded) )
{
GetModuleBaseName( hProcess, hModule, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) );
GetModuleFileNameEx( hProcess, hModule, szFilename, sizeof(szFilename)/sizeof(TCHAR) );
}
CloseHandle( hProcess );
}
_tprintf( TEXT(" %16s %-60s (PID: %u)\n"), szProcessName, szFilename, processID );
}
开发者ID:Grumbel,项目名称:processwatch,代码行数:25,代码来源:processwatch.cpp
示例9: Filter
int Filter(
DWORD pid, char *path
) {
vmdb *vdb = (vmdb *)malloc(sizeof(vmdb));
TCHAR sProcessName[MAX_PATH] = { 0 };
char ctemp[MAX_PATH] = { 0 };
vdb = SetVariable(path);
HANDLE hHandle = OpenProcess(
PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ, FALSE, pid);
if (hHandle) {
GetModuleFileNameEx(hHandle, 0, sProcessName, MAX_PATH);
WideCharToMultiByte(CP_ACP, 0, sProcessName, MAX_PATH, ctemp, MAX_PATH, NULL, NULL);
CloseHandle(hHandle);
for (unsigned int i = 0; i < vdb->num; i++) {
if (strstr(ctemp, vdb->vm_data[i])) {
free(vdb);
return 1;
}
}
}
free(vdb);
return 0;
}
开发者ID:revers3r,项目名称:VMDt,代码行数:25,代码来源:VMprocess.cpp
示例10: GetModules
BOOL GetModules(HANDLE hProcess, char* Strings)
{
DWORD processid[1024], needed, processcount, modulecount;
HMODULE hModule[1024];
DWORD cb = 0;
BOOL ret = 1;
char path[MAX_PATH] = "", temp[MAX_PATH], basename[MAX_PATH];
EnumProcesses(processid, sizeof(processid), &needed);
processcount = 1;// needed/sizeof(DWORD);
for (DWORD i = 0; i< processcount; i++) // 列举一下explorer下的模块
{
if (hProcess)
{
EnumProcessModules(hProcess, hModule, sizeof(hModule), &needed);
modulecount = needed / sizeof(DWORD);
//_itoa(processid[i], temp, 10);
for (DWORD j = 0; j < modulecount; j++)
{
GetModuleFileNameEx(hProcess, hModule[j], path, sizeof(path));
GetModuleBaseName(hProcess, hModule[j], basename, sizeof(basename));
GetShortPathName(path, path, 256);
if(!strcmp(basename, Strings))
{
ret = 1;
}
printf("%s\t\t%s\n", basename, path);
}
}
}
return ret;
}
开发者ID:zephyrer,项目名称:ab-mfc,代码行数:35,代码来源:Taskmgr.cpp
示例11: getModulePid
HMODULE getModulePid(DWORD processID, wchar_t* searchStr){ // gets the module by the module name from an explicit process
HANDLE hProcess;
HMODULE hMods[1024];
TCHAR szModName[MAX_PATH];
DWORD cbNeeded;
if (hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID))
{
if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
{
unsigned int k;
for (k = 0; k < (cbNeeded / sizeof(HMODULE)); ++k)
{
if (GetModuleFileNameEx(hProcess, hMods[k], szModName, sizeof(szModName) / sizeof(TCHAR)))
{
//printf( "fess pid: %u modname: %s\n", processID, szModName );
if (wcsstr(szModName, searchStr))
{
//printf("pid: %u modname: %s\n", processID, szModName);
CloseHandle(hProcess);
return hMods[k];
}
}
}//for
}
}
CloseHandle(hProcess);
return NULL;
}
开发者ID:jongheean11,项目名称:Expandable,代码行数:32,代码来源:E_Util.cpp
示例12: GetCurrentProcessId
std::string
ArchSystemWindows::getLibsUsed(void) const
{
HMODULE hMods[1024];
HANDLE hProcess;
DWORD cbNeeded;
unsigned int i;
char hex[16];
DWORD pid = GetCurrentProcessId();
std::string msg = "pid:" + std::to_string((_ULonglong)pid) + "\n";
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
if (NULL == hProcess) {
return msg;
}
if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) {
for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) {
TCHAR szModName[MAX_PATH];
if (GetModuleFileNameEx(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR))) {
sprintf(hex,"(0x%08X)",hMods[i]);
msg += szModName;
msg.append(hex);
msg.append("\n");
}
}
}
CloseHandle(hProcess);
return msg;
}
开发者ID:335,项目名称:synergy,代码行数:34,代码来源:ArchSystemWindows.cpp
示例13: GetProcessNameByProcessID
void GetProcessNameByProcessID( DWORD processID, CString& szProcessName)
{
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID );
// Get the process name.
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
char str[MAX_PATH] = "unknown";
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) )
{
GetModuleFileNameEx( hProcess, hMod, str, sizeof(str) );
szProcessName.Format("%s", str);
}
}
else
return;
CloseHandle( hProcess );
//return szProcessName;
}
开发者ID:haokeyy,项目名称:fahister,代码行数:25,代码来源:WindowHelp.cpp
示例14: GetProcessFileName
static std::string GetProcessFileName(DWORD processID)
{
std::string result = "";
HANDLE hProcess = OpenProcess(
SYNCHRONIZE | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE, processID);
if (hProcess != NULL)
{
// Here we call EnumProcessModules to get only the
// first module in the process this is important,
// because this will be the .EXE module for which we
// will retrieve the full path name in a second.
HMODULE hMod;
char szFileName[MAX_PATH];
DWORD dwSize2 = 0;
LPTSTR pszName = NULL;
if (EnumProcessModules(hProcess, &hMod,
sizeof(hMod), &dwSize2))
{
// Get Full pathname:
if (GetModuleFileNameEx(hProcess, hMod,
szFileName, sizeof(szFileName)))
result = std::string(szFileName);
}
}
return result;
}
开发者ID:redheli,项目名称:ogre,代码行数:30,代码来源:OgreNsightChecker.cpp
示例15: IsAlreadyPatched
// Check to see if fledge is already patched
BOOL IsAlreadyPatched(DWORD pid)
{
HANDLE fledge = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
HMODULE *hmArray = (HMODULE *) malloc(sizeof(HMODULE)*MODULE_ARRAY);
DWORD needed;
EnumProcessModules(fledge, hmArray, sizeof(hmArray), &needed);
if (needed > sizeof(hmArray))
{
// we need more memory apparently
free(hmArray);
hmArray = (HMODULE *) malloc(needed);
EnumProcessModules(fledge, hmArray, sizeof(hmArray)*MODULE_ARRAY, &needed);
}
CString fileName;
for (int i = 0; i<needed / sizeof(HMODULE); i++)
{
GetModuleFileNameEx(fledge, hmArray[i], fileName.GetBuffer(MAX_PATH + 1), MAX_PATH);
if (fileName.Find(CString(HOOK_DLLNAME)) > -1)
{
free(hmArray);
return true;
}
}
if (hmArray) free(hmArray);
CloseHandle(fledge);
return false;
}
开发者ID:FredericBouts,项目名称:WebWorks,代码行数:34,代码来源:main.cpp
示例16: memset
DWORD ProcessWatch::GetProcessID()
{
DWORD bytesReturned;
DWORD processID[MAX_BUF_PATH];
memset(processID, 0, MAX_BUF_PATH);
EnumProcesses(processID, MAX_BUF_PATH, &bytesReturned);
int processCount = bytesReturned/sizeof(DWORD);
ProcessInfo processInfo;
for (int i=0; i<processCount; i++)
{
processInfo.processID = processID[i];
HANDLE hProcess;
HMODULE hModule[MAX_BUF_PATH];
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,false,processID[i]);
if(hProcess)
{
//enum process module info
EnumProcessModules(hProcess, hModule, sizeof(hModule), &bytesReturned);
// get the module path
GetModuleFileNameEx(hProcess, hModule[0], processInfo.processPath, MAX_BUF_PATH);
//_tprintf(TEXT("%s --- %d\n"), processInfo.processPath, processID[i]);
}
m_vecProcessInfo.push_back(processInfo);
}
return processCount;
}
开发者ID:yellowbigbird,项目名称:bird-self-lib,代码行数:29,代码来源:ProcessWatch.cpp
示例17: _T
void CBDTWxFrame::OnCallStackListDoubleClicked(wxCommandEvent& event)
{
wxString selection = event.GetString();
TCHAR selectionChar[MAX_PATH];
const wxChar* myStringChars = selection.c_str();
for (uint32_t i = 0; i < selection.Len(); i++)
{
selectionChar[i] = myStringChars [i];
}
selectionChar[selection.Len()] = _T('\0');
// Remove the "line:xxx" suffix from selection.
TCHAR* pLastSpacePos = _tcsstr(selectionChar, _T(" "));
TCHAR* pCurPos = pLastSpacePos;
while (pCurPos != NULL)
{
pLastSpacePos = pCurPos;
pCurPos = _tcsstr(pLastSpacePos + 1, _T(" "));
}
*pLastSpacePos = 0;
FILE* pFile = _tfopen(selectionChar, _T("rb"));
if (pFile != NULL)
{
fclose(pFile);
bool bOpenFileInExistingIDE = false;
if (IsDebuggerPresent() != FALSE)
{
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
if (hProcess != NULL)
{
typedef LONG (WINAPI *PROCNTQSIP)(HANDLE,UINT,PVOID,ULONG,PULONG);
PROCNTQSIP NtQueryInformationProcess = (PROCNTQSIP)GetProcAddress(GetModuleHandle(_T("ntdll")), "NtQueryInformationProcess");
if (NtQueryInformationProcess != NULL)
{
PROCESS_BASIC_INFORMATION pbi;
long status = NtQueryInformationProcess(hProcess, 0, (PVOID)&pbi, sizeof(PROCESS_BASIC_INFORMATION), NULL);
if (status == 0)
{
HANDLE hDebuggerProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ , FALSE, pbi.InheritedFromUniqueProcessId);
if (hDebuggerProcess != NULL)
{
TCHAR processPath[MAX_PATH] = {0};
GetModuleFileNameEx(hDebuggerProcess, NULL, processPath, MAX_PATH);
fclose(pFile);
TCHAR parameter[MAX_PATH];
_stprintf_s(parameter, _T("/Edit \"%s\""), selectionChar);
ShellExecute(NULL, _T("open"), processPath, parameter, NULL, SW_SHOW);
CloseHandle(hDebuggerProcess);
bOpenFileInExistingIDE = true;
}
}
}
}
CloseHandle(hProcess);
}
if (!bOpenFileInExistingIDE)
{
ShellExecute(NULL, _T("open"), selectionChar, NULL, NULL, SW_SHOW);
}
}
}
开发者ID:beyondlwm,项目名称:Beats,代码行数:60,代码来源:MemoryPage.cpp
示例18: GetModuleFileNameEx
//-------------------------------------------------------------------------------
bool CVFXGetModuleName::GetModuleName(CString& sModuleName, HANDLE hHandle /* = NULL*/, HMODULE hModule /* = NULL*/)
{
sModuleName = "";
// Get the process handle
if(! hHandle)
hHandle = ::GetCurrentProcess();
// Get the module handle
if(! hModule)
hModule = ::GetModuleHandle(NULL);
// Have to have process and module handle
if(! hHandle && ! hModule)
return false;
// Get the module name
LPTSTR p = sModuleName.GetBuffer(MAX_PATH + 1);
DWORD rc = GetModuleFileNameEx(hHandle, hModule, p, (DWORD)MAX_PATH);
// Release buffer
sModuleName.ReleaseBuffer();
return rc > 0;
}
开发者ID:gangelo,项目名称:GetVerInfo,代码行数:26,代码来源:VFXGetModuleName.cpp
示例19: _ProcList_GetProcessFileName
BOOL _ProcList_GetProcessFileName (DWORD dwProcessId, LPTSTR szFilename, DWORD nSize)
{
HANDLE hProcess ;
BOOL bSuccess ;
DWORD dwAccess = PROCESS_QUERY_INFORMATION|PROCESS_VM_READ ;
ASSERT (szFilename!=NULL) ;
ASSERT (nSize>0) ;
if( dwProcessId==0 )
return _tcslcpy (szFilename, TEXT("System"), nSize) ;
hProcess = OpenProcess (dwAccess,FALSE,dwProcessId) ;
if( ! hProcess ) {
TRACE_ERROR (TEXT("OpenProcess failed (error=%d)\n"), GetLastError()) ;
return FALSE ;
}
szFilename[0] = 0 ;
bSuccess = GetModuleFileNameEx (hProcess, NULL, szFilename, nSize) ;
if( ! bSuccess )
TRACE_ERROR (TEXT("GetModuleFileNameEx failed (pid=%u, error=%d)\n"),
dwProcessId, GetLastError()) ;
CloseHandle (hProcess) ;
return bSuccess ;
}
开发者ID:340211173,项目名称:hf-2011,代码行数:30,代码来源:ProcList.c
示例20: stringTowstring
list<string> GLDProcessFunc::getPathByName(const string &lpProcessName)
{
list<string> retList;
wstring ws = stringTowstring(lpProcessName);
HANDLE hHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // 为当前系统进程建立快照
DWORD dwId = ::GetCurrentProcessId();// 当前进程的Id
if (INVALID_HANDLE_VALUE != hHandle)// 如果快照建立成功
{
PROCESSENTRY32 stEntry;
stEntry.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hHandle, &stEntry)) //在快照中查找一个进程,stEntry返回进程相关属性和信息
{
do{
if (wcsstr(stEntry.szExeFile, ws.c_str())) // 比较该进程名称是否与strProcessName相符
{
if (dwId != stEntry.th32ProcessID) // 如果相等,且该进程的Id与当前进程不相等,则找到
{
HANDLE h_Process = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, stEntry.th32ProcessID);
if (h_Process != NULL)
{
WCHAR name[MAX_PATH + 1] = { 0 };
GetModuleFileNameEx(h_Process, NULL, name, MAX_PATH + 1);
retList.push_back(wstringTostring(std::wstring(name)));
CloseHandle(h_Process);
}
}
}
} while (Process32Next(hHandle, &stEntry)); //再快照中查找下一个进程。
}
// CloseToolhelp32Snapshot(hHandle); //释放快照句柄。
}
return retList;
}
开发者ID:yiminyangguang520,项目名称:HardwareInfoUtils,代码行数:35,代码来源:GLDProcess.cpp
注:本文中的GetModuleFileNameEx函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论