MFC實現重啓資源管理器

本軟件無需界面,實現重啓 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
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章