vb.net 建立系统本地帐号
做个网站管理的软件,首先是建立独立的帐号
Public Shared Sub Create(ByVal user As String,Byval password as String)
Dim localMachine As New DirectoryEntry("WinNT://" & Environment.MachineName)
Dim newUser = localMachine.Children.Add(user) '增加用户名
'Dim newUser = localMachine.Children.Find(user) '查找用户,修改时用
'localMachine.Children.Remove(obUser) '删除用户
newUser.Properties("FullName").Add(user) '用户全称
newUser.Invoke("SetPassword", password) '用户密码
newUser.Invoke("Put", "Description", user) '用户详细描述
newUser.Invoke("Put", "PasswordExpired", 0) '用户下次登录不需更改密码
newUser.Invoke("Put", "UserFlags", 66113) '密码永不过期
'设置标记位,&H40 Nochange &H10000 Noexpire
newUser.CommitChanges()
Dim grp As DirectoryEntry = localMachine.Children.Find("Guests", "Group") 'Group组
grp.Invoke("Add", newUser.Path.ToString()) '将用户添加到某组
newUser.Close()
localMachine.Close()
End Sub
Dim localMachine As New DirectoryEntry("WinNT://" & Environment.MachineName)
Dim newUser = localMachine.Children.Add(user) '增加用户名
'Dim newUser = localMachine.Children.Find(user) '查找用户,修改时用
'localMachine.Children.Remove(obUser) '删除用户
newUser.Properties("FullName").Add(user) '用户全称
newUser.Invoke("SetPassword", password) '用户密码
newUser.Invoke("Put", "Description", user) '用户详细描述
newUser.Invoke("Put", "PasswordExpired", 0) '用户下次登录不需更改密码
newUser.Invoke("Put", "UserFlags", 66113) '密码永不过期
'设置标记位,&H40 Nochange &H10000 Noexpire
newUser.CommitChanges()
Dim grp As DirectoryEntry = localMachine.Children.Find("Guests", "Group") 'Group组
grp.Invoke("Add", newUser.Path.ToString()) '将用户添加到某组
newUser.Close()
localMachine.Close()
End Sub