更新exeplorer.exe:shell
一、方法1:spa
void RefreshExplorer() { 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); strcat(strShell,"\\taskkill.exe"); shellExeInfo.lpFile=strShell; shellExeInfo.lpParameters="/F /IM explorer.exe"; ShellExecuteExA(&shellExeInfo); WaitForSingleObject(shellExeInfo.hProcess,INFINITE); GetWindowsDirectoryA(strShell,1024); strcat(strShell,"\\explorer.exe"); WinExec(strShell,SW_SHOW); }
方法2:code
char* tolow(char *s) { int i, j; for (i = 0;i < strlen(s); i++) { for (j = 0;j < strlen(s); j++) if (s[j] >= 'A' && s[j] <= 'Z') s[j] = s[j] - 'A' + 'a'; } return s; } //殺死進程 void kill(char proc[1024]) { HANDLE hSnapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if(hSnapShot == 0) return; PROCESSENTRY32 thePE; thePE.dwSize = sizeof(PROCESSENTRY32); //遍歷正在運行的第一個系統進程 bool Status = Process32First(hSnapShot,&thePE); bool bHaveFlag = false; DWORD ProcessID = 0; while(Status) { //遍歷正在運行的下一個系統進程 Status = Process32Next(hSnapShot,&thePE); char myproc[1024] ; strcpy(myproc,thePE.szExeFile); strcpy(myproc,tolow(myproc));//轉小寫 //找到相應的進程 **.exe if (strcmp(myproc,proc)==0) { bHaveFlag = true; ProcessID = thePE.th32ProcessID; //結束指定的進程 ProcessID if(!TerminateProcess(OpenProcess (PROCESS_TERMINATE||PROCESS_QUERY_INFORMATION,false,ProcessID),0)) //參數爲0,會引發資源管理器自動重啓! { MessageBox(NULL, TEXT("沒法終止指定的進程"), TEXT("提示"), MB_OK); } break; } } CloseHandle(hSnapShot); }