码迷,mamicode.com
首页 > 其他好文 > 详细

小问题总结

时间:2020-01-10 00:45:23      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:efi   ==   path   type   工作   资源   stop   controls   signed   

vmware 没有网,无法桥接?

虚拟网络编辑器->恢复默认设置

再去看网络协议有无vmware bridg。。。 

没有就安装 安不上就重装。。 

-----------------------

win7 win10经常UAC弹窗,还会使很多程序无法自动运行?

win+r  ->gpedit.msc->计算器配置-> windows设置-> 安全设置-> 本地策略-> 安全选项 

用户帐户控制:以管理员批准模式运行所有管理员。。。   禁用

用户帐户控制:用于内置管理员账户的管理员批准模式。。。   禁用

重启

-----------------------------

程序在其他电脑运行缺少dll?

程序拖入Depends.exe 找到缺少的dll 放入程序同目录下再运行程序

---------------------------------

 

 


#include <stdio.h>#include <Windows.h>//#include <TlHelp32.h>//#include <string>//#include   <afx.h>
#include <UserEnv.h>#include <WtsApi32.h>//#include <afx.h>#pragma comment(lib, "UserEnv.lib")#pragma comment(lib, "WtsApi32.lib")
#define SLEEP_TIME 5000 //间隔时间
#define FILE_PATH "C:\\log.txt" //信息输出文件
bool brun = false;
SERVICE_STATUS servicestatus;
SERVICE_STATUS_HANDLE hstatus;
//int WriteToLog(const char* str);
void WINAPI ServiceMain(int argc, char** argv);
void WINAPI CtrlHandler(DWORD request);
static HANDLE hProcess = NULL;


// 突破SESSION 0隔离创建用户进程  传入程序路径
int WriteToLog(const char* str)
{
FILE* pfile;
fopen_s(&pfile, FILE_PATH, "a+");
if (pfile == NULL)
{
return -1;
}
fprintf_s(pfile, "%s\n", str);
fclose(pfile);
return 0;
}
const char* itoa1(int val){static char result[sizeof(int) << 3 + 2];unsigned int tempval = val;if (val < 0) tempval = -val;int i = sizeof(int) << 3 + 1;do {result[i] = "0123456789"[tempval % 10];tempval /= 10; --i;} while (tempval);if (val < 0) result[i--] = ‘-‘;return &result[i + 1];}
HANDLE CreateUserProcess(char *lpszFileName){BOOL bRet = TRUE;DWORD dwSessionID = 0;HANDLE hToken = NULL;HANDLE hDuplicatedToken = NULL;LPVOID lpEnvironment = NULL;STARTUPINFO si = { 0 };PROCESS_INFORMATION pi = { 0 };si.cb = sizeof(si);
do{// 获得当前Session IDdwSessionID = ::WTSGetActiveConsoleSessionId();//LPCSTR err = _T("ERROR");


WriteToLog("sessionS");
// 获得当前Session的用户令牌if (FALSE == ::WTSQueryUserToken(dwSessionID, &hToken)){int i = GetLastError();
WriteToLog("WTSQueryUserToken");WriteToLog(itoa1(i));bRet = FALSE;return NULL;}
// 复制令牌if (FALSE == ::DuplicateTokenEx(hToken, MAXIMUM_ALLOWED, NULL,SecurityIdentification, TokenPrimary, &hDuplicatedToken)){int i = GetLastError();
WriteToLog("DuplicateTokenEx");WriteToLog(itoa1(i));bRet = FALSE;return NULL;}
// 创建用户Session环境if (FALSE == ::CreateEnvironmentBlock(&lpEnvironment,hDuplicatedToken, FALSE)){int i = GetLastError();
WriteToLog("CreateEnvironmentBlock");WriteToLog(itoa1(i));
bRet = FALSE;return NULL;}
//L"calc.exe"// 在复制的用户Session下执行应用程序,创建进程if (FALSE == ::CreateProcessAsUser(hDuplicatedToken,lpszFileName, NULL, NULL, NULL, FALSE,NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT,lpEnvironment, NULL, &si, &pi)){int i = GetLastError();
WriteToLog("CreateProcessAsUser");WriteToLog(itoa1(i));bRet = FALSE;return NULL;}WriteToLog("sessionC");
} while (FALSE);// 关闭句柄, 释放资源if (lpEnvironment){::DestroyEnvironmentBlock(lpEnvironment);}if (hDuplicatedToken){::CloseHandle(hDuplicatedToken);}if (hToken){::CloseHandle(hToken);}return pi.hProcess;}


void WINAPI ServiceMain(int argc, char** argv){WriteToLog("smain");
servicestatus.dwServiceType = SERVICE_WIN32;
servicestatus.dwCurrentState = SERVICE_START_PENDING;
servicestatus.dwControlsAccepted = SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP ;//只接受系统关机和停止服务两种控制命令
servicestatus.dwWin32ExitCode = 0;
servicestatus.dwServiceSpecificExitCode = 0;
servicestatus.dwCheckPoint = 0;
servicestatus.dwWaitHint = 0;
hstatus = ::RegisterServiceCtrlHandler("boot", CtrlHandler);
if (hstatus == 0){int i = GetLastError();WriteToLog(itoa1(i));WriteToLog("RegisterServiceCtrlHandler failed");
return;
}
WriteToLog("RegisterServiceCtrlHandler success");
//向SCM 报告运行状态
servicestatus.dwCurrentState = SERVICE_RUNNING;
if (!SetServiceStatus(hstatus, &servicestatus)){int i = GetLastError();WriteToLog(itoa1(i));WriteToLog("SetServiceStatus failed");
return;
}
//在此处添加你自己希望服务做的工作,在这里我做的工作是获得当前可用的物理和虚拟内存信息
brun = true;

while (brun){WriteToLog("while1");

//循环开启WriteToLog("yunxing_a");//WinExec("C:\\Windows\\hexin.exe", SW_MAX);char a[] = "C:\\Windows\\hexin.exe";hProcess = CreateUserProcess(a);WriteToLog("yunxing_b");
WaitForSingleObject(hProcess, INFINITE);CloseHandle(hProcess);hProcess = NULL;

Sleep(SLEEP_TIME);

}
WriteToLog("service stopped");
}
void WINAPI CtrlHandler(DWORD request){// 停止服务switch (request){case SERVICE_CONTROL_STOP:
brun = false;
servicestatus.dwCurrentState = SERVICE_STOPPED;
break;
case SERVICE_CONTROL_SHUTDOWN:
brun = false;
servicestatus.dwCurrentState = SERVICE_STOPPED;
break;
default:
break;
}
SetServiceStatus(hstatus, &servicestatus);}
int main(){

SERVICE_TABLE_ENTRY entrytable[2];
const char* constc = "boot";
char* c = nullptr;
c = const_cast<char*>(constc);

entrytable[0].lpServiceName = c;
entrytable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;
entrytable[1].lpServiceName = NULL;
entrytable[1].lpServiceProc = NULL;
StartServiceCtrlDispatcher(entrytable);return 0;
}



小问题总结

标签:efi   ==   path   type   工作   资源   stop   controls   signed   

原文地址:https://www.cnblogs.com/moshuixiong/p/12174037.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!