WellsCarrie
Well-known member
I have a windows form where administrators will enter user information and when submitted will create a local machine user (not active directory). I can create the user, but have been unable to set the password to NEVER expire.
this is a requirement for the server of our RF Guns; each user must have a local (non network) account on the server in order to sign into the RF Guns. The passwords have to be set to never expire or the users get unexpectedly booted from the guns.
I am using this to create the user:
However I can find no way to set the Password to never expire.
I have also tried:
But it always returns this error: Active Directory Not implemented
I do not want an Active Directory account, only a local machine user.
does anyone have working VB code that will do this or know where I can get it?
this is a requirement for the server of our RF Guns; each user must have a local (non network) account on the server in order to sign into the RF Guns. The passwords have to be set to never expire or the users get unexpectedly booted from the guns.
I am using this to create the user:
VB.NET:
Private Function CreateLocalUser(ByVal userAcct As String, ByVal userName As String, _
ByVal password As String, ByVal homedir As String, _
ByVal desc As String) As Boolean
Dim bol As Boolean = True
Try
Dim MyProc As New System.Diagnostics.Process()
MyProc.StartInfo.WorkingDirectory = "C:\WINDOWS\SYSTEM32\"
MyProc.StartInfo.FileName = "net.exe"
MyProc.StartInfo.UseShellExecute = False
MyProc.StartInfo.RedirectStandardError = True
MyProc.StartInfo.RedirectStandardInput = True
MyProc.StartInfo.RedirectStandardOutput = True
MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
MyProc.StartInfo.Arguments = " user " & userAcct & " " & password & " /ADD /ACTIVE:YES " & _
"/EXPIRES:NEVER /FULLNAME:""" & userName & _
""" /HOMEDIR:""" & homedir & """ /PASSWORDCHG:NO /PASSWORDREQ:YES" & _
" /PASSWORDEXP:NO /COMMENT:""" & desc & """"
MyProc.Start()
MyProc.WaitForExit()
MyProc.Close()
Catch ex As Exception
bol = False
rtbNotes.AppendText(vbCrLf)
rtbNotes.AppendText(ex.Source)
rtbNotes.AppendText(vbCrLf)
rtbNotes.AppendText(ex.Message)
End Try
Return bol
End Function
I have also tried:
VB.NET:
Private Function CreateWinUser(ByVal username As String, ByVal password As String, _
ByVal description As String, ByVal homeDir As String, _
ByVal fullname As String) As Boolean
Dim bol As Boolean = True
Try
'Initiate DirectoryEntry Class To Connect Through WINNT Protocol
Dim enTryString As String = "WinNT://" + Environment.MachineName + ",computer"
Dim dirEnTry As DirectoryEntry = New DirectoryEntry(enTryString)
'Search If Specified User Already Exists
Dim userFound As Boolean = False
Try
If Not dirEnTry.Children.Find(username, "user") Is Nothing Then
userFound = True
End If
Catch
userFound = False
End Try
If Not userFound Then
Dim NewUser As DirectoryEntry = New DirectoryEntry(enTryString)
NewUser.Children.Add(username, "user") 'Add user
NewUser.CommitChanges()
If description.Trim() <> "" Then
NewUser.Invoke("Description", New Object() {description})
End If
NewUser.Invoke("FullName", New Object() {fullname})
NewUser.Invoke("homedir", New Object() {homeDir})
'1. User Can not Change Password
NewUser.Invoke("Put", New Object() {"userFlags", "0x000000040"})
'2. Password Never Expires
NewUser.Invoke("Put", New Object() {"userFlags", "0x00010000"})
NewUser.Invoke("SetPassword", New Object() {password}) 'Set password
NewUser.CommitChanges()
End If
Catch ex As Exception
bol = False
rtbNotes.ForeColor = Color.Red
rtbNotes.Clear()
rtbNotes.AppendText(vbCrLf)
rtbNotes.AppendText("ERROR:")
rtbNotes.AppendText(vbCrLf)
rtbNotes.AppendText(ex.Source)
rtbNotes.AppendText(vbCrLf)
rtbNotes.AppendText(ex.Message)
End Try
Return bol
End Function
I do not want an Active Directory account, only a local machine user.
does anyone have working VB code that will do this or know where I can get it?