Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Vista Newsgroups > Vista account administration

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

Reply
 
Old 03-23-2007   #1 (permalink)
Karlo Klenk


 
 

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

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!

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
The User Profile Service service failed the logon. User Profile cannot be loaded Vista file management
The User Profile Service service failed the logon. User Profile cannot be loaded General Discussion
Solved 'The User Profile Service service failed the logon' and forgotten password????? General Discussion
renaming Local user account and Changing "Full Name" of same Local VB Script
Determine if user contained in Log On As A Service local policy... VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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