Jump to content

Recommended Posts

Posted

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

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



×
×
  • Create New...