Wednesday, December 30, 2009

Create Local Win NT User, Windows User

Two quick and easy methods of creating local NT users.  The samples (DOS and VBS) below create a user on the local system, the VBS method check to see if the user exists before adding.

DOS:
NET USER DosUser UserPassword /add

VBS:

Set WshNetwork = CreateObject("WScript.Network")
strComputerName = WshNetwork.ComputerName 'getting the machine name
strUserName="VbsUser"
strPassword="UserPassword"
checkuser = 1 
Set objComputer = GetObject("WinNT://" & strComputerName)
objComputer.Filter = Array("User")
For Each objUser In objComputer
    If (objUser.Name = strUserName) And (checkuser = 1) Then 
       checkuser = 0
   End If
Next

If checkuser = 1 Then
   Set colaccounts = GetObject("WinNT://" & strComputerName & ",computer")
   Set objUser = colaccounts.Create("user", strUserName)
   objUser.SetPassword strPassword
   objUser.SetInfo
End If
Post a Comment