本文整理汇总了C++中GetModuleBaseName函数的典型用法代码示例。如果您正苦于以下问题:C++ GetModuleBaseName函数的具体用法?C++ GetModuleBaseName怎么用?C++ GetModuleBaseName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetModuleBaseName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ret
HMODULE ChildProcessManager::GetChildProcessMainModule() const
{
HMODULE ret(NULL);
if (IsChildProcessCreated())
{
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE,
m_piProcInfo->dwProcessId
);
if (hProcess != INVALID_HANDLE_VALUE)
{
char lpBaseName[MAX_PATH];
CProcessModuleIterator pmi(m_piProcInfo->dwProcessId);
for (HMODULE hModule = pmi.First(); hModule; hModule = pmi.Next())
{
if (GetModuleBaseName(hProcess, hModule, lpBaseName, MAX_PATH))
{
std::string moduleName(lpBaseName);
if (moduleName.find(".exe") != std::string::npos)
{
ret = hModule;
break;
}
}
}
CloseHandle(hProcess);
}
}
return ret;
}
示例2: GetProcessID
ULONG GetProcessID(LPCSTR TargetProcessName)
{
DWORD nSize = MAX_PATH;
HANDLE hCurrentProcess;
CHAR BaseName[MAX_PATH];
DWORD aProcesses[1024], cbNeeded;
unsigned int i;
if (!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded))
return FALSE;
// NumberProcesses = nSize = cbNeeded / sizeof(DWORD);
for (i = 0; i <= nSize; i++)
{
if(NULL != (hCurrentProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, aProcesses[i])))
{
GetModuleBaseName(hCurrentProcess, NULL, BaseName, sizeof(BaseName));
if(0 == stricmp(BaseName, TargetProcessName))
{
CloseHandle(hCurrentProcess);
return aProcesses[i];
}
}
CloseHandle(hCurrentProcess);
}
return FALSE;
}
示例3: getModuleBase
DWORD getModuleBase(const std::string& sModuleName, HANDLE hProc)
{
HMODULE *hModules = nullptr;
char buffer[64];
DWORD modules_size;
DWORD result = -1;
if (!EnumProcessModules(hProc, hModules, 0, &modules_size))
{
std::cout << "Error: EnumProcessModules failed: " << GetLastError() << std::endl;
return 0;
}
hModules = new HMODULE[modules_size / sizeof(HMODULE)];
if (EnumProcessModules(hProc, hModules, modules_size / sizeof(HMODULE), &modules_size))
{
for (unsigned int i = 0; i < modules_size / sizeof(HMODULE); i++)
{
if (GetModuleBaseName(hProc, hModules[i], buffer, sizeof(buffer)))
{
if (strcmp(sModuleName.c_str(), buffer) == 0)
{
result = (DWORD)hModules[i];
break;
}
}
}
}
delete[] hModules;
return result;
}
示例4: PrintProcessNameAndID
void PrintProcessNameAndID( DWORD processID )
{
char szProcessName[MAX_PATH] = "unknown";
// 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;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
}
else return;
}
else return;
// Print the process name and identifier.
printf( "%s (Process ID: %u)\n", szProcessName, processID );
CloseHandle( hProcess );
}
示例5: printProcessInfo
void printProcessInfo(DWORD processID)
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
// 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; // An array that receives the list of module handles.
DWORD cbNeeded; //The number of bytes required to store all module handles in the Module array
if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded)) {
GetModuleBaseName(hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR));
}
}
// Print the process name and identifier of matching strings, ignoring case
_tprintf(TEXT("%s (PID: %u)\n"), szProcessName, processID);
// Release the handle to the process.
CloseHandle( hProcess );
}
示例6: GetProcessId
int GetProcessId(const char* file_name)
{
const int maximum_processes = 1024;
LPDWORD process_ids;
LPTSTR base_name;
HANDLE process;
DWORD i, processes, process_id = 0;
process_ids = (LPDWORD)HeapAlloc(GetProcessHeap(), 0, maximum_processes * sizeof(DWORD));
if(process_ids != NULL) {
if(EnumProcesses(process_ids, maximum_processes * sizeof(DWORD), &processes)) {
base_name = (LPTSTR)HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(TCHAR));
if(base_name != NULL) {
processes = processes / sizeof(DWORD);
for(i = 0; i < processes; i++) {
process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, process_ids[i]);
if(process != NULL) {
if(GetModuleBaseName(process, NULL, base_name, MAX_PATH) > 0) {
if(!lstrcmpi(base_name, file_name)) {
process_id = process_ids[i];
CloseHandle(process);
break;
}
}
CloseHandle(process);
}
}
HeapFree(GetProcessHeap(), 0, (LPVOID)base_name);
}
}
HeapFree(GetProcessHeap(), 0, (LPVOID)process_ids);
}
return process_id;
}
示例7: startDaemonScan
void startDaemonScan()
{
PVOID buffer = VirtualAlloc(NULL, 1024 * 1024, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
while (1)
{
DWORD procIDsBuffer[MAX_PROCESSES];
DWORD size_returned;
EnumProcesses(procIDsBuffer, sizeof(procIDsBuffer), &size_returned);
int numProc = size_returned / sizeof(DWORD);
int i;
TCHAR strBuffer[MAX_PATH];
for (i = 0; i < numProc; i++)
{
DWORD curr_pid = (int)procIDsBuffer[i];
HANDLE Handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, TRUE, curr_pid);
GetModuleBaseName(Handle, NULL, strBuffer, MAX_PATH);
if ((Handle) && isInFrobProcList(strBuffer))
reactToProcess(curr_pid, strBuffer);
CloseHandle(Handle);
}
updateList();
}
}
示例8: kill_process
void kill_process(string name)
{
#ifdef _WIN32
CHAR szProcBuff[101];
DWORD pIDs[300], dwBytesReturned;
HANDLE hProcess;
INT i, procCount;
EnumProcesses(pIDs, sizeof(pIDs), &dwBytesReturned);
procCount = dwBytesReturned / sizeof(DWORD);
for (i = 0; i < procCount; i++)
if (pIDs[i] != 0)
{
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE, 0, pIDs[i]);
GetModuleBaseName(hProcess, 0, szProcBuff, 100);
if (strcmp(szProcBuff, name.c_str()) == 0)
TerminateProcess(hProcess, EXIT_SUCCESS);
CloseHandle(hProcess);
}
#elif __APPLE__
string command = "killall -kill " + name;
system(command.c_str());
#endif
while (process_running(name.c_str()) > 0)
Sleep(1);
}
示例9: MatcProcessImageName
bool MatcProcessImageName(DWORD dwProcId,const TCHAR* tcImageName, bool bTestRunning=false)
{
if(NULL == tcImageName) return false;
HANDLE hProc = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcId );
bool bHasName= false;
bool bResult = false;
TCHAR tcModuleName[MAX_PATH];
if (NULL != hProc ) {
if(bTestRunning) {
DWORD ExitCode = 0;
if(GetExitCodeProcess(hProc, &ExitCode)) {
if (STILL_ACTIVE != ExitCode) return false;
} else {
if(WAIT_TIMEOUT != WaitForSingleObject(hProc, 0)) return false;
}
}
HMODULE hMod;
DWORD nRetCountMod = 0;
if(EnumProcessModules(hProc, &hMod, sizeof(hMod), &nRetCountMod)){
bHasName = (0 != GetModuleBaseName( hProc, hMod, tcModuleName, sizeof(tcModuleName)/sizeof(TCHAR) ) );
} else {
bHasName = (0 != GetProcessImageFileName(hProc, tcModuleName, sizeof(tcModuleName)/sizeof(TCHAR)) ) ;
}
}
if(bHasName) {
const TCHAR *pExeName = _tcsrchr(tcModuleName, TEXT('\\'));
pExeName = (pExeName) ? ++pExeName : tcModuleName;
bResult = (0 == StrCmpI(pExeName,tcImageName));
}
CloseHandle(hProc);
return bResult;
}
示例10: sizeof
bool CallStack::loadAllModules()
{
#ifdef WIN32
DWORD dwNeeded = 0;
if (!EnumProcessModules(hProcess, hModule, sizeof(hModule), &dwNeeded)) return false;
const int iCount = dwNeeded / sizeof(HMODULE);
for (int i = 0; i < iCount; ++i)
{
MODULEINFO info;
GetModuleInformation(hProcess, hModule[i], &info, sizeof(info));
GetModuleFileNameEx(hProcess, hModule[i], szImageName, iMax);
GetModuleBaseName(hProcess, hModule[i], szModuleName, iMax);
#ifdef X64
SymLoadModule64(hProcess, hModule[i], szImageName, szModuleName, (DWORD64)info.lpBaseOfDll, info.SizeOfImage);
#else
SymLoadModule(hProcess, hModule[i], szImageName, szModuleName, (DWORD)info.lpBaseOfDll, info.SizeOfImage);
#endif
}
#endif
return true;
}
示例11: process_name
NSHARE::CText process_name(int processID)
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
// Get a handle to the process.
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE, processID);
// Get the process name.
if (INVALID_HANDLE_VALUE != hProcess)
{
HMODULE hMod;
DWORD cbNeeded;
//Given a handle to a process, this returns all the modules running within the process.
//The first module is the executable running the process,
//and subsequent handles describe DLLs loaded into the process.
if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
{
//This function returns the short name for a module,
//typically the file name portion of the EXE or DLL
GetModuleBaseName(hProcess, hMod, szProcessName,
sizeof(szProcessName) / sizeof(TCHAR));
}
}
NSHARE::CText _text(szProcessName);
//close the process handle
CloseHandle(hProcess);
return _text;
}
示例12: 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 );
}
示例13: EnumProcesses
BOOL CSelectProcessDlg::OnInitDialog(void)
{
CDialog::OnInitDialog();
// initialization
DWORD cbNeeded;
EnumProcesses(procs, sizeof(procs), &cbNeeded);
numprocs = cbNeeded / sizeof(DWORD);
HANDLE hProcess;
HMODULE hMod;
wchar_t str[255];
for (int i = 0; i < numprocs; i++)
{
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, procs[i]);
if (hProcess)
{
if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
{
GetModuleBaseName(hProcess, hMod, str, 255);
m_cmbProcesses.AddString(str);
m_cmbProcesses.SetItemDataPtr(m_cmbProcesses.GetCount() - 1, (void*)&procs[i]);
}
CloseHandle(hProcess);
}
}
return TRUE;
}
示例14: TEXT
void ProcessFinder::PrintProcessNameAndID( DWORD processID )
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
// 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;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR) );
}
}
// Print the process name and identifier.
std::map<std::string,int>::iterator it = processes.find(szProcessName);
if(it!=processes.end())
{
(*it).second++;
}
else
{
std::pair<std::string,int> elem;
elem.first = szProcessName;
elem.second = 1;
processes.insert(elem);
}
CloseHandle( hProcess );
}
示例15: GetDestinationFileName
std::wstring GetDestinationFileName()
{
std::wstring baseName;
//get from file name of this executable
{
std::wstring moduleBaseName = GetModuleBaseName();
std::wstring moduleBaseNameLower = moduleBaseName;
for(int n = 0; n < (int)moduleBaseNameLower.length(); n++)
moduleBaseNameLower[n] = tolower(moduleBaseNameLower[n]);
int index = (int)moduleBaseNameLower.find(_T("_mono"));
if(index == -1)
{
MessageBox(0, _T("Invalid executable file name.\n\nDemands file name in format \"{destination base file name}_mono[any characters].exe\"."),
_T("Mono launcher error"),
MB_OK | MB_ICONEXCLAMATION);
return _T("");
}
baseName = moduleBaseName.substr(0, index);
}
return baseName + _T(".exe");
//return GetModuleFullDirectory() + _T("\\") + baseName + _T(".exe");
}