Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a windows user account from access?

Status
Not open for further replies.

juddymarch

Technical User
Aug 10, 2007
17
Hi, I have computer running "windows server 2003 Standard edition."

In order to create a new user account I go through the process of: Start/Control Panel/Administrative Tool/Computer Management then
Under System Tools/Local Users and Groups/Users/Add new user.

I need to be able to automate this process from within an access form? I cant seem to find code to do it, I have been playing around with the following code but no luck.


Dim Container
Dim ContainerName
Dim User
Dim NewUser
ContainerName = InputBox("Enter the Domain Name:")
NewUser = InputBox("Enter the new user name:")
Set Container = GetObject("WinNT://" & ContainerName)
Set User = Container.Create("User", NewUser)
User.SetInfo

I'm abit lost as to what domain name to enter. And don't even know if the code would work if I have the correct domain name. Any advice would be greatly appreciated.

Thanks
Justin



 
I have managed to get working with the code I had (I was entering the wrong domain) found it by going into command prompt and running 'set'.
My next issue is how can I assign the user go a group? and set their startup program?
 
These are command line utilities, but you can build the code in a string and use VBA's Shell function to get the operating system to run it:

To add a user:

NET USER username password /ADD

to add a user to a group:

NET LOCALGROUP Groupname username /Add

I haven't yet figured out how to set the startup program, but perhaps somebody else can help.

Please note that for this to work, your Access application needs to be running from user who has permissions to do this (Administrator or Account Operator in Windows).

John
 
thanks for the reply jrbarnett. After sh*t loads of googling, I managed to get it working with the following code: (might come in handy for someone in the future)
Private Sub Command1_Click()
Dim Container
Dim ContainerName
Dim User
Dim NewUser
Dim Group
ContainerName = InputBox("Enter the Domain Name:")
NewUser = InputBox("Enter the new user name:")
Set Container = GetObject("WinNT://" & ContainerName)
'Set Container = GetObject("WinNT://Owner")
Set User = Container.Create("User", NewUser)

User.FullName = "test company name"
User.Description = "test description"
User.SetPassword "test password"
User.SetInfo


Set Group = GetObject("WinNT://" & ContainerName & "/" & "Users")
'Set objUser = GetObject("WinNT://" & strComputer & "/" & strUserName1)
'Set User = GetObject("WinNT://" & strComputer & "/" & strUserName1)
Group.Add (User.ADsPath)

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top