+ Post New Thread
Results 1 to 3 of 3
Scripts Thread, user account creation (with options) in Coding and Web Development; Greetings, I have found a nice simple script which lets me add a local user and puts him into a ...
  1. #1

    Join Date
    Oct 2008
    Location
    Southampton, England
    Posts
    204
    Thank Post
    37
    Thanked 8 Times in 6 Posts
    Rep Power
    13

    user account creation (with options)

    Greetings,

    I have found a nice simple script which lets me add a local user and puts him into a specified group. I need this script to be able to change options on the account such as password expiry, whether or not the user can change the password and so on. I dont really know anything about scripting so your help would be great.

    ' ------- TEXT USED ----------
    Title = "New User Tools v1.1"
    strGroup = "Administrators"
    ' ------ END TEXT USED --------
    '---- RETRIEVE COMPUTER NAME ---------
    Dim objNetwork, strComputerName
    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName
    '---- END RETRIEVE COMPUTER NAME --------
    '------ GET INPUTS FROM USER ----------
    Dim strUserName, strFullName, strPassword
    If Msgbox("Would you Like to Add a User?" , vbYesNo, Title) = vbYes then
    Call GetInputs
    Else Call Rename_Computer
    Sub GetInputs
    Do
    strUserName = InputBox("Please Enter User Name.",Title)
    If strUserName = ""Then
    If MsgBox("Are you Sure you want to Quit?" , vbYesNo, Title)= VbNo Then
    Else Call Rename_Computer()
    End If
    End if
    Loop Until strUserName <> ""
    Do
    strFullName = InputBox("Please Enter Your Full Name.", Title)
    If strFullName = "" Then
    If MsgBox("Are you Sure you want to Quit?" , vbYesNo, Title)= VbNo Then
    Else Call Rename_Computer
    End If
    End If
    Loop Until strFullName <> ""
    Do
    strPassword = InputBox("Please Enter Password.",Title)
    If strPassword="" Then
    If MsgBox("Are you Sure you want to Quit?" , vbYesNo, Title)= VbNo Then
    Else Call Rename_Computer
    End If
    End If
    Loop Until strPassword<>""
    Call AddUser()
    End Sub
    ' ------ END INPUTS ---------------
    ' ----- CODE TO ADD USER ----------
    Sub AddUser
    Set objSystem = GetObject("WinNT://" & strComputer)
    Set objUser = objSystem.Create("user", strUserName)
    objUser.FullName = strFullName
    objUser.SetPassword strPassword
    objUser.SetInfo
    Call MsgBox ("User Name: " & strUserName & vbCrLf & "Password: " &strPassword & VbCrLf & VbCrLf & "Please Write This Information Down.", 64, Title)
    Call AddGroup
    End Sub
    ' ----- END CODE TO ADD USER -------
    ' ----- CODE TO ADD USER TO GROUP -------
    Sub AddGroup
    Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup)
    objGroup.Add("WinNT://" & strComputer & "/" & strUserName)
    Call Rename_Computer()
    End Sub
    ' ----- END CODE TO ADD USER TO GROUP -----
    ' ------ RENAME COMPUTER ------
    Sub Rename_Computer
    Dim strNewComputer, objNetwork, objWMIService, colComputers
    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colComputers = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
    If Msgbox("Would you Like to Change the Computer Name?" , vbYesNo, Title) = vbNo Then
    Call CleanUp()
    Else Do
    strNewComputer = InputBox("Please Enter a New Computer Name.",Title)
    If strNewComputer = "" Then
    If MsgBox("Are you Sure you want to Quit?" , vbYesNo, Title)= VbYes Then
    Call CleanUp()
    End If
    End If
    Loop Until strNewComputer <>""
    For Each objComputer in colComputers
    err = objComputer.Rename (strNewComputer)
    Next
    End If
    Call Reboot()
    End Sub
    '------ END RENAME COMPUTER -----------
    '------ REBOOT MACHINE -------------
    Sub Reboot
    If Msgbox("Your Computer Needs to Reboot Before Changes Can be Made. " & vbCrLf & "Would you Like To Reboot Now?" , vbYesNo, Title) = vbYes then
    Dim oWMI, oOS, obj
    Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown )}!\\.\root\cimv2")
    On Error GoTo 0
    For Each obj in oWMI.ExecQuery("Select * from Win32_OperatingSystem")
    Set oOS = obj
    Exit For
    Next
    Call ShutDownNow()
    End If
    End Sub
    Sub ShutDownNow
    Const EWX_LOGOFF = 0
    Const EWX_SHUTDOWN = 1
    Const EWX_REBOOT = 2
    Const EWX_FORCE = 4
    Const EWX_POWEROFF = 8
    oOS.Win32shutdown EWX_REBOOT '+ EWX_FORCE
    End Sub

    ' ------- END ROOT MACHINE ---------

    '------ EXIT -----

    Sub CleanUp
    Call MsgBox ("Click OK To Exit the Program",0, Title)
    WScript.quit
    End Sub
    End If
    '----- EXIT ------

    This is the code, copied from My First Script - Create New Local User Account and/or Change Local Computer Name as a nod to the creator (hope im not doing anything wrong here).

    Cheers
    James

  2. #2

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,168
    Thank Post
    98
    Thanked 319 Times in 261 Posts
    Blog Entries
    4
    Rep Power
    113
    Scripting Local Users using VBScript

    That might be useful as a starting point. And the Scripting Guys have quite a lot of stuff on setting user account flags - Welcome to the Script Center

    Also very useful is the ADSI Scriptomatic -ADSI (Active Directory Service Interfaces) Scriptomatic
    Last edited by jamesb; 3rd June 2009 at 03:04 PM.

  3. Thanks to jamesb from:

    jjohnsoncantell (3rd June 2009)

  4. #3

    Join Date
    Oct 2008
    Location
    Southampton, England
    Posts
    204
    Thank Post
    37
    Thanked 8 Times in 6 Posts
    Rep Power
    13

    many thanks

    Many thanks Jamesb, that was exactly what i needed and i even learned a bit more about scripting, you're a star!

SHARE:
+ Post New Thread

Similar Threads

  1. Bulk user Creation
    By Jamie_a in forum Windows
    Replies: 10
    Last Post: 14th January 2009, 06:30 PM
  2. bulk user creation
    By jonbones in forum Network and Classroom Management
    Replies: 1
    Last Post: 18th June 2008, 10:43 AM
  3. New intake account creation
    By sLiDeR in forum Network and Classroom Management
    Replies: 2
    Last Post: 31st August 2007, 10:54 PM
  4. Exchange 2003 Account Creation Problems
    By paul in forum Windows
    Replies: 2
    Last Post: 22nd November 2006, 03:17 PM
  5. Bulk user creation
    By Dos_Box in forum How do you do....it?
    Replies: 63
    Last Post: 13th November 2006, 07:02 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •