views:

447

answers:

2

I've got this weird problem - I'm calling ChangeServiceConfig on a newly installed service (I CreateService it myself) to supply the logon credentials, but while the function succeeds (returns TRUE), if I try to start the service, it fails with a 1069 (logon failed). If I go into the service manager and modify credentials by hand (I can see the user name is correct, but of course can't see the password), then it's all ok and it starts ok.

The call itself is trivial:

ChangeServiceConfig(hService, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, strUser, strPassword, NULL);

Any ideas on where I should be looking and what could be wrong?

Thanks in advance.

+1  A: 

The user account must explicitly have rights to log on as a service (SeServiceLogonRight). Many users, including computer admins, may not have this flag set, and you may need to set it manually. The windows services control panel actually does this silently behind the scenes when you use it to configure services.

I also have some vague foggy memories about needing to fully qualify the username. It needs to be in DOMAIN\Username format - If it's a local account you need to specify .\Username or find out the machine name and use MACHINENAME\Username

Orion Edwards
Thank you. I think I just found what the problem is, it is actually the LOG_ON_AS_SERVICE rights - http://support.microsoft.com/kb/q132958/, I'll give it a try and see if that solves it.
dennisV
Yep, it was the LOG_ON_AS_SERVICE user rights not being set. I really wish this was documented somewhere in the CreateService/ChangeServiceConfig documentation before I started pulling my hair out :)
dennisV
A: 

using \Username worked for me! thanks for this :)