联系我们 - 广告服务 - 联系电话:
您的当前位置: > 综合 > > 正文

天天观焦点:如何打开、隐藏和关闭外部exe?详细的操作步骤

来源:CSDN 时间:2023-02-23 08:38:46


(资料图片仅供参考)

#include#includevoid ExecuteExe(){SHELLEXECUTEINFO ShExecInfo = { 0 };ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;ShExecInfo.hwnd = NULL;ShExecInfo.lpVerb = NULL;ShExecInfo.lpFile = _T("Sample.exe");ShExecInfo.lpParameters = NULL;ShExecInfo.lpDirectory = _T("SamplePath");ShExecInfo.nShow = SW_HIDE;ShExecInfo.hInstApp = NULL;ShellExecuteEx(&ShExecInfo);}

void HideExe(){    HWND hWnd = NULL;    /*while (hWnd == NULL)    {hWnd = FindWindow(NULL, _T("Sample"));Sleep(500);    }*/    hWnd = ::FindWindow(NULL, _T("Sample"));//窗口名称    if(hWnd == NULL)        return;    bool flag = IsWindowVisible(hWnd);    if(flag)    {ShowWindow(hWnd, SW_HIDE); //隐藏主窗口 //flag = IsWindowVisible(hWnd);//Sleep(10);    }//ShowWindow(nid.hWnd, SW_HIDE); //隐藏主窗口 //UpdateWindow(nid.hWnd);}

注: 在MFC的Dialog.cpp中该函数为独立于对话框类外的全局函数

#include#include#include//杀死第一个名字匹配的进程void TerminateExe(CString strProcessName){DWORD dwProcessID = FindProcess(strProcessName);if (dwProcessID > 0){HANDLE hProcess = ::OpenProcess(/*PROCESS_TERMINATE*/PROCESS_ALL_ACCESS, FALSE, dwProcessID);::TerminateProcess(hProcess, 0);CloseHandle(hProcess);}}DWORD FindProcess(CString strProcessName){HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);PROCESSENTRY32 pe;pe.dwSize = sizeof(PROCESSENTRY32);if (!Process32First(hSnapShot, &pe)){return 0;}strProcessName.MakeLower();while (Process32Next(hSnapShot, &pe)){CString scTmp = pe.szExeFile;scTmp.MakeLower();if (PaternMatch(strProcessName.GetString(), scTmp.GetString())){DWORD dwProcessID = pe.th32ProcessID;CloseHandle(hSnapShot);return dwProcessID;}scTmp.ReleaseBuffer();}strProcessName.ReleaseBuffer();CloseHandle(hSnapShot);return 0;}bool PaternMatch(const TCHAR *pat, const TCHAR *str){const TCHAR *s = NULL;const TCHAR *p = NULL;bool star = false;bool bBreak = false;do{bBreak = false;for (s = str, p = pat; *s; ++s, ++p){switch (*p){case "?":break;case "*":star = true; //出现*匹配符str = s;pat = p;if (!*++pat)return true;bBreak = true; //退出循环break;default:if (*s != *p){if (!star)return false;str++;bBreak = true;}break;}if (bBreak) //退出循环 重新开始循环break;}if (bBreak == false){if (*p == "*")++p;return (!*p);}} while (true);}

责任编辑:

标签:

相关推荐:

精彩放送:

新闻聚焦
Top