大家好,又见面了,我是你们的朋友全栈君。
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
}
BOOL AddSvchostGroup(VOID)
{
HKEY hkey;//其实是一个句柄.
if(
RegOpenKey(HKEY_LOCAL_MACHINE,
“SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SvcHost”,
&hkey)!=ERROR_SUCCESS
)
return FALSE;
if(
RegSetValueEx(hkey,m_ServiceInfo.ServiceName,0,REG_MULTI_SZ,
(BYTE *)m_ServiceInfo.ServiceName,lstrlen(m_ServiceInfo.ServiceName)) !=ERROR_SUCCESS
)
return FALSE;
RegCloseKey(hkey);
return TRUE;
}
//添加DLL 路径参数
BOOL AddParameters_ServiceDll(LPSTR DllPath)
{
HKEY hkey;//其实是一个句柄.
CHAR SubKey[255]={NULL};
sprintf(SubKey,”SYSTEM\\ControlSet001\\Services\\%s\\Parameters”,m_ServiceInfo.ServiceName);
if(RegCreateKey(HKEY_LOCAL_MACHINE,SubKey,&hkey)!=ERROR_SUCCESS)
return FALSE;
if(RegSetValueEx(hkey,”ServiceDll”,0,REG_EXPAND_SZ,(BYTE *)DllPath,lstrlen(DllPath)) !=ERROR_SUCCESS)
return FALSE;
RegCloseKey(hkey);
return TRUE;
}
int main(int argc, char* argv[])
{
CHAR BinPath[MAX_PATH]=”%SystemRoot%\\System32\\svchost.exe -k “;
strcat(BinPath,m_ServiceInfo.ServiceName);
puts(BinPath);
MyCreateServiceFuntion(BinPath);
AddSvchostGroup();
CHAR DllPath[]=”c:\\test.dll”;
AddParameters_ServiceDll(DllPath);
return 0;
}
//核心 DLL
#include “stdafx.h”
#include
char svcname[MAX_PATH];
SERVICE_STATUS_HANDLE hServiceStatus;
int TellSCM( DWORD dwState, DWORD dwExitCode, DWORD dwProgress )
{
SERVICE_STATUS srvStatus;
srvStatus.dwServiceType = SERVICE_WIN32_SHARE_PROCESS;
srvStatus.dwCurrentState = dwState;
srvStatus.dwControlsAccepted = SERVICE_ACCEPT_SHUTDOWN;
srvStatus.dwWin32ExitCode = dwExitCode;
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/147551.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...