一段重启WinCE下explorer.exe的代码

C/C++ code
   
   
   
   
// 请在前边加上 tlhelp32.h和toolhelp.lib void CResAdjustDlg::RestartExplorer() { // 获取进程快照 HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0 ); if (INVALID_HANDLE_VALUE == hSnapshot) { MessageBox(_T( " Get processes snapshot failure. " ), _T( " ERROR " ), MB_ICONERROR | MB_OK); return ; } PROCESSENTRY32 pe32; BOOL bRet = FALSE; BOOL bFirst = TRUE; DWORD dwExplorerProcId = (DWORD) - 1 ; memset( & pe32, 0x00 , sizeof (PROCESSENTRY32)); pe32.dwSize = sizeof (PROCESSENTRY32); // 遍历进程 for ( ; ; ) { __try { if (bFirst) { bRet = Process32First(hSnapshot, & pe32); bFirst = FALSE; } else { bRet = Process32Next(hSnapshot, & pe32); } if ( ! bRet) { if (ERROR_NO_MORE_FILES != GetLastError()) { MessageBox(_T( " Process32First() error. " )); } break ; } // MessageBox(pe32.szExeFile); if (_tcsicmp(_T( " explorer.exe " ), pe32.szExeFile) == 0 ) { dwExplorerProcId = pe32.th32ProcessID; break ; } } __except(EXCEPTION_EXECUTE_HANDLER) { break ; } } if (dwExplorerProcId != (DWORD) - 1 ) { PROCESS_INFORMATION pi; HANDLE hExplorer = OpenProcess( 0 , FALSE, dwExplorerProcId); if (hExplorer != NULL) { TerminateProcess(hExplorer, 1 ); if ( ! CreateProcess(_T( " explorer.exe " ), NULL, NULL, NULL, FALSE, 0 , NULL, NULL, NULL, & pi)){ MessageBox(_T( " Create explorer.exe process failure. " )); } else { // MessageBox(_T("Create process success.")); } } CloseHandle(hExplorer); } CloseToolhelp32Snapshot(hSnapshot); }

觉得这段重启进程的代码挺常用的

你可能感兴趣的:(exception,null,WinCE)