vbs脚本创建Windows账户。
1. 弹出对话框提示用户输入用户名和密码,密码隐藏
2. 修改用户的密码永不过期
- dim username, password
- username = "test"
- password = "test"
- password = GetPassword("Enter your password.", username, password)
- useradd username, password
- passwordexpires(username)
- Msgbox("User " + username + " created." )
- WScript.quit
- Function GetPassword( myPrompt, ByRef username, ByRef password)
- ' This function uses Internet Explorer to
- ' create a dialog and prompt for a password.
- '
- ' Version: 2.11
- ' Last modified: 2010-09-28
- '
- ' Argument: [string] prompt text, e.g. "Please enter password:"
- ' Returns: [string] the password typed in the dialog screen
- '
- ' Written by Rob van der Woude
- ' http://www.robvanderwoude.com
- ' Error handling code written by Denis St-Pierre
- Dim objIE
- ' Create an IE object
- Set objIE = CreateObject( "InternetExplorer.Application" )
- ' specify some of the IE window's settings
- objIE.Navigate "about:blank"
- objIE.Document.Title = "User infomation"
- objIE.ToolBar = False
- objIE.Resizable = False
- objIE.StatusBar = False
- objIE.Width = 320
- objIE.Height = 220
- ' Center the dialog window on the screen
- With objIE.Document.ParentWindow.Screen
- objIE.Left = (.AvailWidth - objIE.Width ) \ 2
- objIE.Top = (.Availheight - objIE.Height) \ 2
- End With
- ' Wait till IE is ready
- Do While objIE.Busy
- WScript.Sleep 200
- Loop
- ' Insert the HTML code to prompt for a password
- objIE.Document.Body.InnerHTML = "<div align=""center""><p>" & myPrompt _
- & "</p><p>UserName <input type="""" size=""20"" " _
- & "id=""UserNameInput"">" _
- & "</p><p>Password <input type=""password"" size=""20"" " _
- & "id=""PasswordInput""></p><p><input type=" _
- & """hidden"" id=""OK"" name=""OK"" value=""0"">" _
- & "<input type=""submit"" value="" OK "" " _
- & "onclick=""VBScript:OK.Value=1""></p></div>"
- ' Hide the scrollbars
- objIE.Document.Body.Style.overflow = "auto"
- ' Make the window visible
- objIE.Visible = True
- ' Set focus on password input field
- objIE.Document.All.UserNameInput.Focus
- ' Wait till the OK button has been clicked
- On Error Resume Next
- Do While objIE.Document.All.OK.Value = 0
- WScript.Sleep 200
- ' Error handling code by Denis St-Pierre
- If Err Then 'user clicked red X (or alt-F4) to close IE window
- IELogin = Array( "", "" )
- objIE.Quit
- Set objIE = Nothing
- Exit Function
- End if
- Loop
- On Error Goto 0
- ' Read the password from the dialog window
- GetPassword = objIE.Document.All.PasswordInput.Value
- username = objIE.Document.All.UserNameInput.Value
- password = objIE.Document.All.PasswordInput.Value
- ' Close and release the object
- objIE.Quit
- Set objIE = Nothing
- End Function
- sub useradd(username, password)
- Dim shell
- Set shell = WScript.CreateObject("WScript.Shell")
- shell.Run "net user " + username + " " + password + " /add" , 0, false
- WScript.Sleep 1000
- end sub
- sub passwordexpires(username)
- dim users
- '获取所有用户
- set users = getobject("winmgmts:{impersonationlevel=impersonate}").instancesof("win32_useraccount")
- for each user in users
- if user.name = username then
- '如果和参数指定的用户名相同,则设置密码永不过期
- user.PasswordExpires = False
- '提交刚才的修改
- user.Put_()
- end if
- next
- end sub
本文转自 h2appy 51CTO博客,原文链接:http://blog.51cto.com/h2appy/1101982,如需转载请自行联系原作者