Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Administration > How to use C++ to add a new local user for a service

Reply
Thread Tools Display Modes

How to use C++ to add a new local user for a service

 
 
Karlo Klenk
Guest
Posts: n/a

 
      03-23-2007
Hi folks!

On Vista, I can't seem to have my C++ program add a new user that is usable
for a service, starting the service fails with ERROR_BAD_USER_PROFILE

Here's how I do it:

- Add the user, same code as shown in this place:
http://support.microsoft.com/kb/196070

i.E.: adduser.exe MyServiceUser MyServicePassword

(After this, the profile dir appears in C:\Users\MyServiceUser)


- Give the user the SeServiceLogonRight privilege

(I have verified that this works using the management console)


- Register the service:

CreateService(mgr, // SCManager database
"MyService", // name of service
"Sample Service", // service name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_PROCESS, // service type
SERVICE_DEMAND_START, // start type
SERVICE_ERROR_NORMAL, // error control type
path, // path to service's binary
NULL, // no load ordering group
NULL, // no tag identifier
NULL, // no dependencies
".\\MyServiceUser", // Local system account
"MyServicePassword"); // no password


- Try to start the service: net start MyService
XP: Works
Vista: Fails with 1253: ERROR_BAD_USER_PROFILE


Now if I logon this user once manually at the welcome screen
(which needs some fiddling in the user management console to allow this),
the service can be started.

Thus I conclude there's something missing beyond calling LoadUserProfile(),
but what is it?

Thanks in advance!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: 'User Profile Service service failed the logon Marek Windows Vista General Discussion 18 08-27-2010 04:00 PM
User Profile Service: Service Failed Logon Kinhaven Windows Vista General Discussion 1 02-19-2009 04:09 PM
Error ! User Profile Service service failed the logon. DavidinEdmond Windows Vista Administration 15 07-12-2008 11:45 PM
Local service for printer buffer is not running fubbick74 Windows Vista Printing / Faxing / Scanning 2 02-18-2008 07:14 PM
Re: 'User Profile Service service failed the logon MICHAEL Windows Vista General Discussion 1 02-04-2008 07:00 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59