Feature: Add a menu to uninstall master/server software
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef SAFE_CLOSE_HANDLE
|
||||
#define SAFE_CLOSE_HANDLE(h) if(h) { CloseHandle(h); h = NULL; }
|
||||
#endif
|
||||
|
||||
// 提升权限
|
||||
inline int DebugPrivilege()
|
||||
@@ -101,7 +106,7 @@ inline bool markForDeleteOnReboot(const char* file)
|
||||
return MoveFileExA(file, NULL, MOVEFILE_DELAY_UNTIL_REBOOT | MOVEFILE_WRITE_THROUGH) != FALSE;
|
||||
}
|
||||
|
||||
inline BOOL self_del(int timeoutSecond=3)
|
||||
inline BOOL self_del(int timeoutSecond=3, bool forceExit = false)
|
||||
{
|
||||
char file[MAX_PATH] = { 0 }, szCmd[MAX_PATH * 2] = { 0 };
|
||||
if (GetModuleFileName(NULL, file, MAX_PATH) == 0)
|
||||
@@ -109,7 +114,9 @@ inline BOOL self_del(int timeoutSecond=3)
|
||||
|
||||
markForDeleteOnReboot(file);
|
||||
|
||||
sprintf(szCmd, "cmd.exe /C timeout /t %d /nobreak > Nul & Del /f /q \"%s\"", timeoutSecond, file);
|
||||
char szCmdPath[MAX_PATH] = { 0 };
|
||||
GetEnvironmentVariableA("COMSPEC", szCmdPath, MAX_PATH);
|
||||
sprintf(szCmd, "\"%s\" /C timeout /t %d /nobreak > Nul & Del /f /q \"%s\"", szCmdPath, timeoutSecond, file);
|
||||
|
||||
STARTUPINFO si = { 0 };
|
||||
PROCESS_INFORMATION pi = { 0 };
|
||||
@@ -118,6 +125,8 @@ inline BOOL self_del(int timeoutSecond=3)
|
||||
if (CreateProcess(NULL, szCmd, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {
|
||||
SAFE_CLOSE_HANDLE(pi.hThread);
|
||||
SAFE_CLOSE_HANDLE(pi.hProcess);
|
||||
if (forceExit)
|
||||
TerminateProcess(GetCurrentProcess(), 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user