本软件无需界面,实现重启 explorer.exe进程。
直接上代码,可以写到OnInitDialog()函数中。
BOOL CXXXlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
char strShell[1024];
SHELLEXECUTEINFOA shellExeInfo = {0};
shellExeInfo.cbSize = sizeof(SHELLEXECUTEINFOA);
shellExeInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shellExeInfo.nShow = SW_HIDE;
shellExeInfo.lpVerb = "open";
GetSystemDirectoryA(strShell,1024);
::PathAppendA(strShell,"taskkill.exe");
shellExeInfo.lpFile = strShell;
shellExeInfo.lpParameters = "/F /IM explorer.exe";
ShellExecuteExA(&shellExeInfo);
WaitForSingleObject(shellExeInfo.hProcess,INFINITE);
GetWindowsDirectoryA(strShell,1024);
::PathAppendA(strShell,"explorer.exe");
WinExec(strShell,SW_SHOW);
OnOK();
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}