标签:call nbsp const rar dir tla 出错 wchar create
1 void SelfDestroy() 2 { 3 // temporary .bat file 4 static const WCHAR tempbatname[] = L"_uninsep.bat"; 5 CString csCmd; //bat contents 6 std::string szCmd; 7 8 static WCHAR templ[] = 9 L":Repeat\r\n" 10 L"del \"%s\"\r\n" 11 L"if exist \"%s\" goto Repeat\r\n" 12 L"rmdir \"%s\"\r\n" 13 L"del \"%s\""; 14 15 WCHAR modulename[_MAX_PATH]; // absolute path of calling .exe file 16 WCHAR temppath[_MAX_PATH]; // absolute path of temporary .bat file 17 WCHAR folder[_MAX_PATH]; 18 // absolute path of temporary .bat file 19 GetTempPath(_MAX_PATH, temppath); 20 wcscat_s(temppath, tempbatname); 21 // absolute path of calling .exe file 22 GetModuleFileName(NULL, modulename, MAX_PATH); 23 wcscpy_s(folder, modulename); 24 25 PWCHAR pb = wcsrchr(folder, ‘\\‘); 26 if (pb != NULL) 27 *pb = 0; 28 29 HANDLE hf; 30 31 hf = CreateFile(temppath, GENERIC_WRITE, 0, NULL, 32 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 33 //Long,如执行成功,则返回文件句柄。INVALID_HANDLE_VALUE表示出错,会设置GetLastError。即使函数成功,但若文件存在,且指定了CREATE_ALWAYS 或 OPEN_ALWAYS,GetLastError也会设为ERROR_ALREADY_EXISTS 34 if (hf != INVALID_HANDLE_VALUE) 35 { 36 csCmd.Format(templ, modulename, modulename, folder, temppath); 37 CStringToString(csCmd, szCmd); 38 DWORD len; 39 PWCHAR bat; 40 //缓存大小最大1024 41 WriteFile(hf, szCmd.c_str(), szCmd.size(), &len, NULL); 42 CloseHandle(hf); 43 ShellExecuteW(NULL, L"open", temppath, NULL, NULL, SW_HIDE); 44 } 45 }
标签:call nbsp const rar dir tla 出错 wchar create
原文地址:https://www.cnblogs.com/endenvor/p/12452786.html