获得当前进程名称(Ring3)

CHAR lpExeName [MAX_PATH];//进程名称 xxx.exe
BOOL getCurrentProcessName()
{    
    BOOL bRet = TRUE;
    HWND hCurrentWin = NULL;
    string strFullpathName;
    string strExeName;
    CHAR lpModuleName [MAX_PATH];
    
    memset(lpModuleName,0,MAX_PATH);
    memset(lpExeName,0,MAX_PATH);
    DWORD dwProcId;
    int nIndex = 0; 
    //获得当前模块名称
   if(!GetModuleFileName(NULL,lpModuleName,MAX_PATH))
	{
		MessageBoxA(NULL,"进程名称获取失败","TIP",0);
		return FALSE;
	}

    strFullpathName = lpModuleName;
    //处理字符串
    nIndex = strFullpathName.find_last_of('\\');
    if(nIndex<=0)
    {
        return FALSE;
    }
    strExeName = strFullpathName.substr(nIndex+1,strFullpathName.length());//+1越过'\'
    
    memcpy_s(lpExeName,MAX_PATH,strExeName.data(),MAX_PATH);
    return TRUE;
}

 

你可能感兴趣的:(Windows应用层开发)