最近做项目碰到这个问题,要以某个特定额用户建立一个service并启动起来,service是建好了,但是启动的时候出现logon错误。看起来像是密码不对,其实是用户没有拿到logon的权限,没有很具体看,在stackoverflow上找到解决方案,希望对别人有所帮助。
#define UNICODE
#include <windows.h>
#include <ntsecapi.h>
#include <stdio.h>
#pragma comment(lib, "advapi32")
#define SVCPATH L"D:\\VCProj\\MinSvc2\\Debug\\MinSvc2.exe"
#define SVCNAME L"MyExtra1"
#define SVCACCT L".\\dummy"
#define SVCPASS L"dummy"
void InitLsaString( PLSA_UNICODE_STRING LsaString, LPWSTR String )
{
USHORT StringLength;
if (String == NULL)
{
LsaString->Buffer = NULL;
LsaString->Length = 0;
LsaString->MaximumLength = 0;
return;
}
// Get the length of the string without the null terminator.
StringLength = wcslen(String);
// Store the string.
LsaString->Buffer = String;
LsaString->Length =