Add User Account with a Password to Admin Group

Add User Account with a Password to Admin Group

Post by QnJpYW » Tue, 06 Nov 2007 06:48:00


I would like to add a user account and default password to the local system
administrators group. I realize that this is not the perfect solution to the
problem I have... but it is the best solution in for this beta release.
This software will never be used outside of a "test" lab.

I can add the user using the below code... But how do I assign a default
password?

Set g = GetObject("WinNT://./Administrators")
g.Add "WinNT://JoeBob"
Set g = GetObject("WinNT://./JmpsAdministrator")
g.Add "WinNT://JoeBob"

Thanks,
 
 
 

Add User Account with a Password to Admin Group

Post by Richard Mu » Tue, 06 Nov 2007 08:26:17


Actually, the AdsPath for a local user should include the NetBIOS name of
the computer. A WinNT AdsPath like "WinNT://JoeBob" would refer to either a
computer or domain. You can use the SetPassword method of the user object to
assign a password. I would suggest code similar to:
==========
' Bind to local computer.
strComputer = "."
Set objComputer = GetObject("WinNT://" & strComputer)

' Create local user called JoeBob.
Set objUser = objComputer.Create("user", "JoeBob")

' Enable the user account.
objUser.AccountDisabled = False

' Save the new object.
objUser.SetInfo

' Assign password.
objUser.SetPassword "zyq312v"

' Bind to local Administrators account.
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")

' Add local user JoeBob to the group.
objGroup.Add objUser.AdsPath
===========
objUser.AdsPath will return a string similar to "WinNT://./JoeBob".

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.yqcomputer.com/
--

 
 
 

Add User Account with a Password to Admin Group

Post by QnJpYW » Tue, 06 Nov 2007 08:34:00

Thanks Richard,
That helps and gives me a bit more to work with. Appreciate the suggestions.

B
 
 
 

Add User Account with a Password to Admin Group

Post by Bob Butle » Tue, 06 Nov 2007 09:09:51


The question doesn't makes a lot of sense to me. You can create new users
and set their password. You can add existing users to a group. You can't
add a user & password to a group. What exactly are you trying to
accomplish?
 
 
 

Add User Account with a Password to Admin Group

Post by QnJpYW » Tue, 06 Nov 2007 09:13:03

Richard,
The code you provided generates an error when I try to set the Disabled
property. And if I comment out that code... the SetInfo statement also
fails.

Do I need to Dim the objects as a specific type?

I'll continue to try to troubleshoot... but any thoughts?
 
 
 

Add User Account with a Password to Admin Group

Post by Bob Butle » Tue, 06 Nov 2007 09:27:46


What are the errors?
 
 
 

Add User Account with a Password to Admin Group

Post by QnJpYW » Tue, 06 Nov 2007 09:30:00

I want to add the user to the Admin group, and then assign a default password
for this user. And additionally, uncheck the box that would force the user
to change the password at next login.

I'm using this to get around some web service restrictions when the
Anonymous user account is disabled. So my deployment package will install
this user account on all systems that will be running our web service. And
then the core service will authenticate to each client with this user name
and password.
 
 
 

Add User Account with a Password to Admin Group

Post by Richard Mu » Tue, 06 Nov 2007 23:57:43

The computer object should be IADsContainer. Add a reference in the VB
project to "Active DS Type Library" (activeds.tlb). Then code similar to
below should work. I added code so the new user does not need to change
password at logon.
=============
Dim objComputer As IADsContainer
Dim strComputer As String
Dim objUser As IADsUser
Dim objGroup As IADsGroup

strComputer = "."
Set objComputer = GetObject("WinNT://" & strComputer)

Set objUser = objComputer.Create("user", "TestUser")
objUser.SetInfo
objUser.AccountDisabled = False
objUser.SetInfo

objUser.SetPassword ("xyz123")
objUser.Put "PasswordExpired", CLng(0)
objUser.SetInfo

Set objGroup = GetObject("WinNT://" & strComputer &
"/Administrators,group")
objGroup.Add (objUser.ADsPath)
========
If an error is raised on the first SetInfo statement, it could indicate you
lack permissions.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.yqcomputer.com/