Link to home
Start Free TrialLog in
Avatar of mskohut
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
Avatar of jkr
jkr
Flag of Germany image

>>But what to do if the user does not belong to a domain, but to a workgroup?

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.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mskohut
mskohut

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".