What is the best way to create a local user on the machine with administrator
rights?
I have problems with my code on machines that have password policy. The
problem is that when the user is created there is no password, and password
policy is set to min 7 chars or something. So the code only works if I turn
of group policy. Can I create a user with pass (and even add him to
administrators group) in one line/action? My code:
Private Sub CreateUser(ByVal User As String)
'Create Account
Try
Dim strUser As String = User
Dim oDomain As Object = GetObject("WinNT://" + ComputerName)
Dim oUser As Object = oDomain.Create("user", strUser)
If (Err.Number = 0) Then
oUser.SetInfo()
oUser.SetPassword(Password)
oUser.SetInfo()
SaveLog("Created user " & User)
Else
SaveLog("Unable to create user " & User)
Diagnostics.EventLog.WriteEntry("Rename Tool", "Unable to
create user " & User & " with password " & Password,
EventLogEntryType.Warning)
End If
Catch ex As Exception
SaveLog("Unable to create user " & User & ". More info: " &
ex.Message)
Diagnostics.EventLog.WriteEntry("Rename Tool", "Unable to create
user " & User & " with password " & Password & ".More info: " & ex.Message,
EventLogEntryType.Warning)
End Try
End Sub