本来是想搞个图片显示出来的,但是看雪显示图片要链接。。我就用传附件的格式了。。
///////------------------------------下面是安装服务的代码------------------------------------
BOOL InstallService(LPCTSTR strServiceName,
LPCTSTR strDisplayName,
LPCTSTR strDescription,
LPCTSTR strPathName)
{
BOOL bRet = FALSE;
HKEY key=NULL;
SC_HANDLE svc=NULL, scm=NULL;
__try
{
scm = OpenSCManager(0, 0,SC_MANAGER_ALL_ACCESS);
if (!scm)
__leave;
svc = CreateService(
scm,
strServiceName,
strDisplayName,
SERVICE_ALL_ACCESS|SERVICE_INTERACTIVE_PROCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
strPathName,
NULL, NULL, NULL, NULL, NULL);
if (svc == NULL)
{
if (GetLastError() == ERROR_SERVICE_EXISTS)
{
svc = OpenService(scm,strServiceName,SERVICE_ALL_ACCESS);
if (svc==NULL)
__leave;
else
StartService(svc,0, 0);
return true;
}
}
TCHAR Desc[MAX_PATH];
wsprintf(Desc,_T("SYSTEM\\CurrentControlSet\\Services\\%s"), strServiceName);
RegOpenKey(HKEY_LOCAL_MACHINE,Desc,&key);
RegSetValueEx(key,_T("Description"),0,REG_SZ,(CONST BYTE*)strDescription,(lstrlen(strDescription)+1)*sizeof(TCHAR));
RegSetValueEx(key,_T("ServiceMain"),0,REG_SZ,(CONST BYTE *)L"UCC",(wcslen(L"UCC")+1)*sizeof(TCHAR));
if (!StartService(svc,0, 0))
__leave;
bRet = TRUE;
}
__finally
{
if (key!=NULL)
RegCloseKey(key);
if (svc!=NULL)
CloseServiceHandle(svc);
if (scm!=NULL)
CloseServiceHandle(scm);
}
return bRet;
}
BOOL InstallSvchostService(LPCTSTR strServiceName,
LPCTSTR strDisplayName,
LPCTSTR strDescription,
LPCTSTR strDllPath)
{
int rc = 0;
HKEY hKey = 0;
BOOL bRet = FALSE;
TCHAR szOpenKey[MAX_PATH];
try
{
bRet = InstallService(strServiceName,
strDisplayName,
strDescription,
_T("%SystemRoot%\\System32\\svchost.exe -k rpccss")); //安装服务
//修改dll指向
ZeroMemory(szOpenKey,sizeof(szOpenKey));
wsprintf(szOpenKey, _T("SYSTEM\\CurrentControlSet\\Services\\%s\\Parameters"), strServiceName);
//rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szOpenKey, 0, KEY_ALL_ACCESS, &hKey);
rc = RegCreateKey(HKEY_LOCAL_MACHINE, szOpenKey,&hKey);
if(ERROR_SUCCESS != rc) throw "";
rc = RegSetValueEx(hKey, _T("ServiceDll"), 0, REG_EXPAND_SZ, (unsigned char*)strDllPath, (lstrlen(strDllPath)+1)*sizeof(TCHAR));
SetLastError(rc);
if(ERROR_SUCCESS != rc) throw "RegSetValueEx(ServiceDll)";
RegCloseKey(hKey);
//添加服务名到netsvcs组
ZeroMemory(szOpenKey,sizeof(szOpenKey));
lstrcpy(szOpenKey, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost"));
rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szOpenKey, 0, KEY_ALL_ACCESS, &hKey);
if(ERROR_SUCCESS != rc) throw "RegOpenKeyEx(Svchost)";
rc = RegSetValueEx(hKey, _T("rpccss"), 0, REG_MULTI_SZ, (unsigned char*)strServiceName, (lstrlen(strServiceName)+1)*sizeof(TCHAR));
SetLastError(rc);
if(ERROR_SUCCESS != rc) throw "RegSetValueEx(Svchost\\rpccss)";
RegCloseKey(hKey);
bRet = StartService(strServiceName);
}
catch(char *str)
{
if(str && str[0])
{
rc = GetLastError();
}
}
RegCloseKey(hKey);
return bRet;
}
求来个服务帝指教一下。
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课