mskohut
asked on
CreateService (Platform SDK): Creating a service with a specific account
Hello,
I use the CreateService function of the Platform SDK to create a service that runs under a specific account.
If the user belongs to a domain, I have no problem: In the lpServiceStartName, I use the account name in the form "DomainName\UserName".
But what to do if the user does not belong to a domain, but to a workgroup? I tried "WorkgroupName\UserName" and ".\UserName" for the lpServiceStartName Parameter, but I get error 997 (Overlapped I/O operation is in progress) after the call to CreateService.
I also tried "\UserName", and the CreateService returned no error. But then the OpenService function failed. I got error 1068 (The dependency service or group failed to start). The Logon Service told me in the event log, that the user does not belong to a domain, but to a workgroup.
What's wrong?
I am using MS VC++ 6 and Win 2000.
Thanks,
Markus
I use the CreateService function of the Platform SDK to create a service that runs under a specific account.
If the user belongs to a domain, I have no problem: In the lpServiceStartName, I use the account name in the form "DomainName\UserName".
But what to do if the user does not belong to a domain, but to a workgroup? I tried "WorkgroupName\UserName" and ".\UserName" for the lpServiceStartName Parameter, but I get error 997 (Overlapped I/O operation is in progress) after the call to CreateService.
I also tried "\UserName", and the CreateService returned no error. But then the OpenService function failed. I got error 1068 (The dependency service or group failed to start). The Logon Service told me in the event log, that the user does not belong to a domain, but to a workgroup.
What's wrong?
I am using MS VC++ 6 and Win 2000.
Thanks,
Markus
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
"MachineName\UserName" worked, ".\UserName" not.
Reason:
Before I call CreateService with the account name, I ensure that the account is granted the SE_SERVICE_LOGON privilege.
In doing this, I call LookupAccountName with the account name (lpAccountName). But this function seems only accept account names in the form "DomainName\UserName" or "MachineName\UserName", NOT ".\UserName".
Reason:
Before I call CreateService with the account name, I ensure that the account is granted the SE_SERVICE_LOGON privilege.
In doing this, I call LookupAccountName with the account name (lpAccountName). But this function seems only accept account names in the form "DomainName\UserName" or "MachineName\UserName", NOT ".\UserName".
It has to be of the form
LPCTSTR pszAcctName = ".\\UserName";
>>But then the OpenService function failed.
You have to ensure that the account you are using is granted the SE_SERVICE_LOGON privilege.