vbs脚本创建Windows账户

简介:

vbs脚本创建Windows账户。

1. 弹出对话框提示用户输入用户名和密码,密码隐藏

2. 修改用户的密码永不过期

 
 
  1. dim username, password 
  2. username = "test" 
  3. password = "test" 
  4. password = GetPassword("Enter your password.", username, password) 
  5. useradd username, password 
  6. passwordexpires(username) 
  7. Msgbox("User " + username + " created." ) 
  8. WScript.quit 
  9.  
  10. Function GetPassword( myPrompt, ByRef username, ByRef password) 
  11. ' This function uses Internet Explorer to 
  12. ' create a dialog and prompt for a password. 
  13. ' 
  14. ' Version:             2.11 
  15. ' Last modified:       2010-09-28 
  16. ' 
  17. ' Argument:   [string] prompt text, e.g. "Please enter password:" 
  18. ' Returns:    [string] the password typed in the dialog screen 
  19. ' 
  20. ' Written by Rob van der Woude 
  21. ' http://www.robvanderwoude.com 
  22. ' Error handling code written by Denis St-Pierre 
  23.     Dim objIE 
  24.     ' Create an IE object 
  25.     Set objIE = CreateObject( "InternetExplorer.Application" ) 
  26.     ' specify some of the IE window's settings 
  27.     objIE.Navigate "about:blank" 
  28.     objIE.Document.Title = "User infomation" 
  29.     objIE.ToolBar        = False 
  30.     objIE.Resizable      = False 
  31.     objIE.StatusBar      = False 
  32.     objIE.Width          = 320 
  33.     objIE.Height         = 220 
  34.     ' Center the dialog window on the screen 
  35.     With objIE.Document.ParentWindow.Screen 
  36.         objIE.Left = (.AvailWidth  - objIE.Width ) \ 2 
  37.         objIE.Top  = (.Availheight - objIE.Height) \ 2 
  38.     End With 
  39.     ' Wait till IE is ready 
  40.     Do While objIE.Busy 
  41.         WScript.Sleep 200 
  42.     Loop 
  43.     ' Insert the HTML code to prompt for a password 
  44.     objIE.Document.Body.InnerHTML = "<div align=""center""><p>" & myPrompt _ 
  45.                                   & "</p><p>UserName <input type="""" size=""20"" " _ 
  46.                                   & "id=""UserNameInput"">" _                                  
  47.                                   & "</p><p>Password <input type=""password"" size=""20"" " _ 
  48.                                   & "id=""PasswordInput""></p><p><input type=" _ 
  49.                                   & """hidden"" id=""OK"" name=""OK"" value=""0"">" _ 
  50.                                   & "<input type=""submit"" value="" OK "" " _ 
  51.                                   & "onclick=""VBScript:OK.Value=1""></p></div>" 
  52.     ' Hide the scrollbars 
  53.     objIE.Document.Body.Style.overflow = "auto" 
  54.     ' Make the window visible 
  55.     objIE.Visible = True 
  56.     ' Set focus on password input field 
  57.     objIE.Document.All.UserNameInput.Focus 
  58.  
  59.     ' Wait till the OK button has been clicked 
  60.     On Error Resume Next 
  61.     Do While objIE.Document.All.OK.Value = 0 
  62.         WScript.Sleep 200 
  63.         ' Error handling code by Denis St-Pierre 
  64.         If Err Then    'user clicked red X (or alt-F4) to close IE window 
  65.             IELogin = Array( """" ) 
  66.             objIE.Quit 
  67.             Set objIE = Nothing 
  68.             Exit Function 
  69.         End if 
  70.     Loop 
  71.     On Error Goto 0 
  72.  
  73.     ' Read the password from the dialog window 
  74.     GetPassword = objIE.Document.All.PasswordInput.Value 
  75.     username = objIE.Document.All.UserNameInput.Value 
  76.     password = objIE.Document.All.PasswordInput.Value 
  77.     ' Close and release the object 
  78.     objIE.Quit 
  79.     Set objIE = Nothing 
  80. End Function 
  81.  
  82.  
  83. sub useradd(username, password) 
  84.     Dim shell 
  85.     Set shell = WScript.CreateObject("WScript.Shell")  
  86.     shell.Run "net user " + username + " " + password + " /add" , 0, false  
  87.     WScript.Sleep 1000 
  88. end sub 
  89.  
  90. sub passwordexpires(username) 
  91.     dim users 
  92.     '获取所有用户 
  93.     set users = getobject("winmgmts:{impersonationlevel=impersonate}").instancesof("win32_useraccount"
  94.     for each user in users 
  95.         if user.name = username then 
  96.             '如果和参数指定的用户名相同,则设置密码永不过期 
  97.             user.PasswordExpires = False 
  98.             '提交刚才的修改 
  99.             user.Put_() 
  100.         end if 
  101.     next 
  102. end sub 

 










本文转自 h2appy  51CTO博客,原文链接:http://blog.51cto.com/h2appy/1101982,如需转载请自行联系原作者
目录
相关文章
|
9月前
|
存储 安全 Linux
OpenSSH之Windows账户访问操作
OpenSSH之Windows账户访问操作
203 0
|
1月前
|
Windows
【Windows】 手写脚本更快编辑hosts文件
【Windows】 手写脚本更快编辑hosts文件
23 0
|
2月前
|
弹性计算 安全 数据安全/隐私保护
远程桌面连接Windows实例,提示“为安全考虑,已锁定该用户账户,原因是登录尝试或密码更改尝试过多”错误解决方案
远程桌面连接Windows实例,提示“为安全考虑,已锁定该用户账户,原因是登录尝试或密码更改尝试过多”错误解决方案
281 0
|
2月前
|
数据安全/隐私保护 Windows
Windows Server 2003 搭建邮件服务器实现自建邮箱域名及账户并连接外网
Windows Server 2003 搭建邮件服务器实现自建邮箱域名及账户并连接外网
|
5月前
|
存储 数据可视化 数据库
InfluxData【付诸实践 01】Windows环境部署Telegraf+Influxdb+Grafana安装及使用配置(含百度云盘资源+demo脚本)
InfluxData【付诸实践 01】Windows环境部署Telegraf+Influxdb+Grafana安装及使用配置(含百度云盘资源+demo脚本)
90 0
|
7月前
|
数据安全/隐私保护 Android开发 iOS开发
解决第三方邮箱APP登陆QQ、163邮箱无法验证账户名或密码的问题(IOS、MacOS、Windows、Android)
解决第三方邮箱APP登陆QQ、163邮箱无法验证账户名或密码的问题(IOS、MacOS、Windows、Android)
121 0
|
7月前
|
网络安全 数据安全/隐私保护 Windows
[笔记] Windows VBS脚本实现自动输入 解放双手 自动测试
[笔记] Windows VBS脚本实现自动输入 解放双手 自动测试
149 0
|
7月前
|
安全 数据可视化 Windows
[笔记]Windows安全之《三》Shellcode 补充之 Get-InjectedThread脚本搭建环境及其使用
[笔记]Windows安全之《三》Shellcode 补充之 Get-InjectedThread脚本搭建环境及其使用
|
9月前
|
Windows
太阳当空照-Windows服务化方式脚本封装sc指令(下)
太阳当空照-Windows服务化方式脚本封装sc指令(下)
76 0
|
9月前
|
Windows
太阳当空照-Windows服务化方式脚本封装sc指令(上)
太阳当空照-Windows服务化方式脚本封装sc指令
121 0