WMI script giving up!!!

A

Al

I was looking all day for a script that would add a user
to a LOCAL machine. I finally found one! The only problem
is that I need to create the user in the "Administrators
Group" I edited the script over 100 time and could not
find any documentation on what class to call or anything.

Here is the script:
************
strComputer = "."
Set colAccounts = GetObject("WinNT://" & strComputer
& ",computer")
Set objUser = colAccounts.Create("user", "Admin2")
objUser.SetPassword "sA2xpWh"
objUser.SetInfo
**************

seems simple enough>>

Can anyone help???
 
S

Sass

Al said:
I was looking all day for a script that would add a user
to a LOCAL machine. I finally found one! The only problem
is that I need to create the user in the "Administrators
Group" I edited the script over 100 time and could not
find any documentation on what class to call or anything.

Here is the script:
************
strComputer = "."
Set colAccounts = GetObject("WinNT://" & strComputer
& ",computer")
Set objUser = colAccounts.Create("user", "Admin2")
objUser.SetPassword "sA2xpWh"
objUser.SetInfo
**************

'Determing computer name
Set objNet=CreateObject("wscript.Network")
strComputer=objNet.ComputerName
'Defining "password never expires" constant
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
'creating user
Set colAccounts = GetObject("WinNT://" & strComputer & ",computer")
Set objUser = colAccounts.Create("user","Admin2")
objUser.SetPassword "sA2xpWh"
objUser.SetInfo
Set objUser = Nothing
'putting "password never expires" flag
Set objUser = GetObject("WinNT://" & strComputer & "/Admin2,user")
objUserFlags = objUser.Get("UserFlags")
objPasswordExpirationFlag = objUserFlags OR ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userFlags", objPasswordExpirationFlag
objUser.SetInfo
Set objUser = Nothing
'Adding user Admin2 to administartors group
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/Admin2,user")
objGroup.Add(objUser.ADsPath)
 
B

Brendon Rogers

Why do you expect a script that creates a user to be simple to modiy to add
the user to a group?

Start here:
http://www.microsoft.com/technet/community/scriptcenter/default.mspx

http://www.microsoft.com/technet/community/scriptcenter/user/scrug188.mspx

If you want to learn scripting the I highly recommend following this:
http://www.microsoft.com/resources/documentation/windows/2000/server/scriptguide/en-us/default.mspx

Its well written, easy to follow and will have you up and running very
quickly.
 
A

Al

This script might save me!!! Thanks very much, will test
out in our ENV today. Will report back..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top