Archive: User account manipulation


User account manipulation
Ok... so I have my installer doing most of what it needs to do. But as part of the process I need to create and configure a new windows user account.

I am able to create the account, but then I cannot configure it, because I cannot seem to find a way to make windows create the new user's profile folder and registry hive. I know that this usually requires a human @ keyboard login to happen, but have found several places where people supposedly have programmatical ways to accomplish it.

So far though, none seem to work. Has anyone here managed to make this work?


CancerFace put up this very extensive page:
http://nsis.sourceforge.net/User_Man...sing_API_calls

Stu


I had already found that page, and it does have lots of good stuff. But my user creation is already working. What's got me stumped is a way to prod windows into initializing all the user's local stuff (reg. hive, personal folders, desktop, etc.) once I've created it.


Have a look at this page. It explains a bit the process of getting a profile upon your first logon. Although the above page refers to a domain setup the same things apply to your local station.

I would think, without having tested this, that once you create the account, you should be able to impersonate the user calling LogonUser and use the resulting token in order to manually generate/edit the profile of this user. I am not sure if LogonUser will in fact copy the profile of the new user to the right place though.

What I have done in the past in a domain (and I do not see a reason why it should not work on a standalone PC) after creating the account, is to copy manually the default user profile to the new user's profile directory, apply ownership to the new user, then edit the user hive and change ownership + replace certain values in the registry to reflect the new username. All this with the build in windows tools (xcopy, cacls, subinacl, reg) and rather easy cmd scripts ... I am sure all this can be achieved with fancy API calls within an NSIS installer :)

Hope this helps,
CF


Is there anything over and above getting the machine name and calling the CreateUser macro?

If creating the user does not work (i.e. the new user does not appear in the Manage Computer console after Refreshing the view after running the installer), how do I go about debugging it?

Cheers,
jc


The macros should work, unless you are calling them using an account with limited privileges. (I hope you are not trying this in 95/98/ME by the way)

Try adding some error checking after every API call. For example if you call NetUserAdd get the error code as well:

...
System::Call 'netapi32::NetUserAdd(w "${SERVER_NAME}",i 1,i R0,*i.r0) i.r1 ?e'
Pop $9
...
and check to see what it is, in case the call fails

CF