Jump to content

Adding users as local users


Recommended Posts

I have been banging my head against the wall for days now trying to figure out how to add 300 users as local users to a Windows 2003 server. The original post is #143645. What I need to do is copy from a .cvs file the user's first and last name, their logon name and their password. The only bit of code that has worked for me has been this bit of vbs script.

strComputer = "sdsnawp2"
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "aesparza")
Set objGroup = GetObject("WinNT://" & strComputer & "/Users,group")
objUser.SetPassword "mj679s"
objUser.SetInfo
objGroup.Add(objUser.ADsPath)

I can't seem to figure out how to apply any of the autoit scripts offered in the post mentioned above to solve this problem.

Link to post
Share on other sites
  • Developers

I have been banging my head against the wall for days now trying to figure out how to add 300 users as local users to a Windows 2003 server. The original post is #143645. What I need to do is copy from a .cvs file the user's first and last name, their logon name and their password. The only bit of code that has worked for me has been this bit of vbs script.

strComputer = "sdsnawp2"
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "aesparza")
Set objGroup = GetObject("WinNT://" & strComputer & "/Users,group")
objUser.SetPassword "mj679s"
objUser.SetInfo
objGroup.Add(objUser.ADsPath)

I can't seem to figure out how to apply any of the autoit scripts offered in the post mentioned above to solve this problem.

What is the layout of the file ? can you show few records ?

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

It is by first name, last name, log on name, password and description, which is a way of identifying what group each user belongs to.

First Name,Last Name,Login Name,Password,Description
Aldo,Fernandez,afernandez,america9,SCB
Alejandro,Arias,aarias,311212ab,SCB
Angel,Vieyra,avieyra,colceacini,SCB
Anita,Ibarra,aibarra,sbptiw,SCB
Carlos,Pazariz,cpazariz,mfmymc,SCB
Celia,Smith,csmith,yspgxh,SCB
Edith,Valenzuela,evalenzuela,edithvale,SCB
Link to post
Share on other sites
  • Developers

Here's a start to get you going...

$file = FileOpen("users.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
; Read the titkeline
$line = FileReadLine($file)
If @error = -1 Then Exit
; Init objects
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 
$strComputer = @ComputerName
$colAccounts = ObjGet("WinNT://" & $strComputer & "")
$objGroup = ObjGet("WinNT://" & $strComputer & "/Users,group")
; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
; Split record on comma: First Name,Last Name,Login Name,Password,Description
    $Userinfo = StringSplit($line,",")
    $objUser = $colAccounts.Create("user", $Userinfo[3])
    $objUser.SetPassword ($Userinfo[4])
    $objUser.SetInfo
    $objGroup.Add($objUser.ADsPath)
Wend
FileClose($file)
;
;
; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1); something to check for when this function returns 
Endfunc
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

I am using your suggestion and am getting the error "unknown function name" at ObjEvent in this line of code.

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler

I am using AutoIt version 3.1.1 and there is no reference to ObjEvent in the help file. Is this part of the beta version of AutoIt?

Link to post
Share on other sites

I am using your suggestion and am getting the error "unknown function name" at ObjEvent in this line of code.

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler

I am using AutoIt version 3.1.1 and there is no reference to ObjEvent in the help file. Is this part of the beta version of AutoIt?

beta is required
Link to post
Share on other sites

Thank you both, it worked perfectly with the beta version! Now if I could impose upon you for two more things. How do I get the first and last name inserted as full name and the description added when the user account is created?

Link to post
Share on other sites
  • Developers

Thank you both, it worked perfectly with the beta version! Now if I could impose upon you for two more things. How do I get the first and last name inserted as full name and the description added when the user account is created?

come on... you have the basics running so just a bit of research should give you the info needed....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

Thank you both, it worked perfectly with the beta version! Now if I could impose upon you for two more things. How do I get the first and last name inserted as full name and the description added when the user account is created?

To go just a little bit further than JdeB, you need to take a look at $objUser.FullName and $objUser.Description....

Fully automatic, comes in any sizeMakes me wonder what I did before I got synchronized...

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...