用vbs和ADSI管理Windows账户
ADSI (Active Directory Services Interface)是Microsoft新推出的一项技术,它统一了许多底层服务的编程接口,程序员可以使用一致的对象技术来访问这些底层服务。 ADSI把这些服务的公共部分提取出来,同时隔离出相异的部分,程序员可以用统一的接口访问底层服务的公共部分,并延伸到底层服务的专有部分。
管理用户组
获取用户组的用户列表
Dim oGrp
Dim oUser
Dim sDomain
dim sMsg
sDomain = "localhost"
On Error Resume Next Set oGrp = GetObject("WinNT://"&sDomain&"/Administrators,group")
For Each oUser In oGrp.Members
sMsg = sMsg & oUser.Name & "(" & oUser.Class & ") " & oUser.ADsPath & vbnewline
Next
msgbox sMsg If (Err.Number<>) Then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
End If
Set oGrp = Nothing
Set oUser = Nothing
另一种方法:
Dim oDomain
Dim oGrp
Dim oUser
Dim sDomain
dim sMsg
sDomain = "localhost"
On Error Resume Next Set oDomain = GetObject("WinNT://"&sDomain)
Set oGrp = oDomain.GetObject("group", "Administrators") For Each oUser In oGrp.Members
sMsg = sMsg & oUser.Name & "(" & oUser.Class & ") " & oUser.ADsPath & vbnewline
Next
msgbox sMsg If (Err.Number<>) Then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
End If
Set oGrp = Nothing
Set oUser = Nothing
查询用户是否属于该用户组
Dim oGrp
On Error Resume Next Set oGrp = GetObject("WinNT://localhost/Administrators")
MsgBox oGrp.IsMember("WinNT://DESKTOP-K3O4FGP/Administrator") If (Err.Number<>) Then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
End If
Set oGrp = Nothing
添加用户到用户组
该操作要求当前登录用户为Administrator。
Dim oGrp
dim sDomain
sDomain = "DESKTOP-K3O4FGP"
Set oGrp = GetObject("WinNT://"&sDomain&"/Administrators")
oGrp.Add ("WinNT://"&sDomain&"/Admin") if (Err.Number<>) then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
else
msgbox "Complete"
end if
Set oGrp = Nothing
从用户组中移除用户
该操作要求当前登录用户为Administrator。
Dim oGrp
dim sDomain
sDomain = "DESKTOP-K3O4FGP"
On Error Resume Next Set oGrp = GetObject("WinNT://"&sDomain&"/Administrators")
oGrp.Remove ("WinNT://"&sDomain&"/jeffsmith") If (Err.Number<>) Then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
else
msgbox "Complete"
End If
Set oGrp = Nothing
创建用户组
该操作要求当前登录用户为Administrator。
Dim oDomain
Dim oGroup
Dim sDomain
sDomain = "localhost"
On Error Resume Next
Set oDomain = GetObject("WinNT://"&sDomain)
Set oGroup = oDomain.Create("group","MyGroup")
oGroup.SetInfo if (Err.Number<>) then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
else
msgbox "Complete"
end if
Set oGroup = Nothing
Set oDomain = Nothing
删除用户组
该操作要求当前登录用户为Administrator。
Dim oDomain
Dim sDomain
sDomain = "localhost"
On Error Resume Next
Set oDomain = GetObject("WinNT://"&sDomain)
oDomain.Delete "group","MyGroup" if (Err.Number<>) then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
else
msgbox "Complete"
end if
Set oDomain = Nothing
管理用户
添加用户
该操作要求当前登录用户为Administrator。
Dim oDomain
Dim oUser
Dim sDomain
sDomain = "localhost"
On Error Resume Next Set oDomain = GetObject("WinNT://"&sDomain)
Set oUser = oDomain.Create("user","jeffsmith")
'oUser.FullName = "FullName" '用户全名
'oUser.Description = "Description" '描述
'oUser.SetPassword "password" '设置密码
'oUser.PasswordExpired = 1 '下次登录需要更改密码
'oUser.UserFlags = oUser.UserFlags Or &H10000
'&H20000(下次登录须更改密码)
'&H0040(用户不能更改密码)
'&H10000(密码永不过期)
'&H0002(账户已禁用)
oUser.SetInfo if (Err.Number<>) then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
else
msgbox "Complete"
end if
如果未设置用户属性,则 新建的用户的默认属性如下:
Property | Value |
---|---|
Full Name | SAM Account Name (such as jeffsmith) |
Password | Empty |
User Must Change Password | TRUE |
User Cannot Change Password | FALSE |
Password Never Expires | FALSE |
Account Disabled | FALSE |
Group | Domain User |
Profile | Empty |
Account Never Expires | TRUE |
修改用户属性
该操作要求当前登录用户为Administrator。
Dim oUser
Dim sDomain
sDomain = "localhost"
On Error Resume Next
Set oUser = GetObject("WinNT://"&sDomain&"/jeffsmith") oUser.FullName = "jeffsmith"
oUser.Description = "Description"
oUser.AccountDisabled = False
oUser.IsAccountLocked = False
oUser.SetInfo if (Err.Number<>) then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
else
msgbox "Complete"
end if
用户属性详见:https://docs.microsoft.com/zh-cn/windows/win32/adsi/iadsuser-property-methods
设置用户密码
该操作要求当前登录用户为Administrator。
Dim oUser
Dim sDomain
sDomain = "localhost"
On Error Resume Next
Set oUser = GetObject("WinNT://"&sDomain&"/jeffsmith") oUser.SetPassword "pa55w0rd!" if (Err.Number<>) then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
else
msgbox "Complete"
end if
更改用户密码
该操作要求当前登录用户为Administrator。
Dim oUser
Dim sOldPass
Dim sNewPass
Dim sDomain
sDomain = "localhost"
On Error Resume Next Set oUser = GetObject("WinNT://"&sDomain&"/JeffSmith,user")
' Add code to securely retrieve the old and new password.
oUser.ChangePassword sOldPass, sNewPass if (Err.Number<>) then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
else
msgbox "Complete"
end if
Set oUser = Nothing
删除用户
该操作要求当前登录用户为Administrator。
Dim oDomain
Dim sDomain
sDomain = "localhost"
On Error Resume Next Set oDomain = GetObject("WinNT://"&sDomain)
oDomain.Delete "user", "jeffsmith" if (Err.Number<>) then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
else
msgbox "Complete"
end if
查询用户隶属的组
Dim oUser
Dim oGroup
Dim sDomain
Dim sMsg
sDomain = "localhost"
On Error Resume Next
Set oUser = GetObject("WinNT://"&sDomain&"/Administrator") For Each oGroup In oUser.Groups
sMsg = sMsg & oGroup.Name & vbnewline
Next if (Err.Number<>) then
MsgBox("An error has occurred. " &vbnewline& Err.Description)
else
msgbox sMsg
end if
引用:https://docs.microsoft.com/zh-cn/windows/win32/adsi/adsi-objects-of-winnt
用vbs和ADSI管理Windows账户的更多相关文章
- Windows账户管理
windows账户管理 最近部署人员给我们提了一个需求,就是希望简化部署过程. 为了能够远程桌面控制终端电脑,他们需要为每台终端设置进行一些设置,例如创建用户名和密码,开启允许 远程桌面设置,以及开机 ...
- 玩转Windows服务系列——命令行管理Windows服务
说到Windows服务的管理就不得不说通过命令行的方式管理Windows服务,因为无论是系统管理员,还是通过编程的方式调用cmd命令,命令行都是非常方便以及强大的工具. 接下来就看一下如何通过cmd命 ...
- 使用Chef管理windows集群
但凡服务器上了一定规模(百台以上),普通的ssh登录管理的模式就越来越举步维艰.试想Linux发布了一个高危漏洞的补丁,你要把手下成百上千台机器都更新该补丁,如果没有一种自动化方式,那么至少要耗上大半 ...
- 使用Chef管理windows集群 | 运维自动化工具
但凡服务器上了一定规模(百台以上),普通的ssh登录管理的模式就越来越举步维艰.试想Linux发布了一个高危漏洞的补丁,你要把手下成百上千台机器都更新该补丁,如果没有一种自动化方式,那么至少要耗上大半 ...
- 玩转Windows服务系列——命令行管理Windows服务
原文:玩转Windows服务系列——命令行管理Windows服务 说到Windows服务的管理就不得不说通过命令行的方式管理Windows服务,因为无论是系统管理员,还是通过编程的方式调用cmd命令, ...
- [转帖]Ansible管理windows集群
Ansible管理windows集群 http://www.cnblogs.com/Dev0ps/p/10026908.html 写的挺好的 我关注点还是不够好呢 最近公司新项目需要安装400+win ...
- 厉害—Ansible管理windows集群
最近公司新项目需要安装400+windows server 2012系统的工作站,想着怎么能像linux下运用ansible批量管理,linux就很简单了有ssh服务 但是下却没这么简单,但还是有办法 ...
- [转帖]Ansible批量远程管理Windows主机(部署与配置)
2018-09-12 12:04:42 https://blog.51cto.com/7424593/2174156 一.测试环境介绍 Ansible管理主机: 系统: CentOS6.8 IP ...
- Ansible 批量管理Windows Server服务器
Ansible批量管理Windows Server Ansible是一款为类Unix系统开发的自由开源的配置和自动化工具, 它用Python写成,类似于saltstack和Puppe ...
随机推荐
- 使用create-react-app+react-router-dom+axios+antd+react-redux构建react项目
1.安装.构建 # 全局安装 npm install -g create-react-app # 构建一个my-app的项目 npx create-react-app my-app cd my-app ...
- 更改Dynamics 365 Customer Engagement本地部署的高级配置
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- Office2019新增哪些功能
上一篇文章我们知道了office为什么没有2017/2018版本,那个是因为微软office是时隔三年一更新的软件,这不office2019就出来了.一款软件,只有不断的完善自身功能,进行不断的更新, ...
- 关于Mysql修改帐号密码的多种方法
方法一: 登录Mysql进行修改(mysql的小黑框) 命令: set password for 用户名(一般为root) @localhost=password('新密码'); 方法二: 登录MyS ...
- java 实现文件下载中文名不显示
需要将指定字符串的编码转换成浏览器里面的ISO-8859-1编码 String name = new String(name.getBtes("utf-8"),"ISO- ...
- .NET Core 数据结构与算法 1-1
.NET Core 数据结构与算法 1-1 本节内容为顺序表 简介 线性表是简单.基本.常用的数据结构.线性表是线性结构的抽象 (Abstract),线性结构的特点是结构中的数据元素之间存在一对一的线 ...
- ASP.NET Core部署系列二:发布到CentOS上
前言: 在上一节中,通过一系列的步骤,已经将项目部署到IIS上,虽然遇到了一些问题,但最终解决并成功运行了.而在这一节中,将尝试通过linux系统的环境下,部署项目,实现Net Core跨平台的亮点. ...
- PDF转换成DXF文件?PDF转DXF的操作方法
在CAD工作中,经常就需要将绘制完成的图纸文件的格式进行转换,那怎么将PDF文件转换成DXF格式的呢?具体要怎么来进行操作呢?本编教程小编就来教教大家具体操作方法,具体操作如下: 一.工具转换 推荐指 ...
- Linux 资源监控整体分析-TOP
一.top 第一行,任务队列信息,同 uptime 命令的执行结果 系统时间:15:23:10 运行时间:up 236 day,4min, 当前登录用户: 2个 user 负载均衡(uptime) ...
- FCC---Create Texture by Adding a Subtle Pattern as a Background Image
One way to add texture and interest to a background and have it stand out more is to add a subtle pa ...