用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 ...
随机推荐
- 「SAP技术」如何看Z移动类型是复制哪个标准移动类型而创建的?
[SAP技术]SAP MM 如何看一个自定义移动类型是复制哪个标准移动类型而创建的? 比如项目上有一个自定义移动类型Z59,是复制551移动类型而定义的. OMJJ配置界面里,是有一个Ref字段.如下 ...
- MySQL8.0+常用命令
开启远程访问 通过以下命令开启root用户远程访问权限: CREATE USER 'root'@'%' IDENTIFIED BY 'password'; GRANT ALL ON *.* TO 'r ...
- 苹果_公司开发者账号_申请DUNS number
申请DUNS number 注意事项:a.公司英文名称,例如:北京京城科技有限公司,Beijing Jingcheng Technology Co., Ltd.(Co.和Ltd.都是缩写,中间用“逗号 ...
- 痞子衡嵌入式:飞思卡尔i.MX RTyyyy系列MCU启动那些事(2)- Boot配置(BOOT Pin/eFUSE)
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是飞思卡尔i.MX RTyyyy系列MCU的Boot配置. 在上一篇文章 Boot简介 里痞子衡为大家介绍了Boot基本原理以及i.MXR ...
- ubuntu18.04因java路径原因启动jenkins失败
我的云服务器ubuntu18.04上本来装了jenkins,今天安装完tomcat后,将原有的openjdk卸载了,安装了jdk8u192, 此时浏览器访问8080端口显示的就是tomcat安装成功的 ...
- CSV和JSON格式相互转换
1.为什么要进行CSV与JSON格式之间的转换 CSV格式常用于一二维数据表示和存储,他是一种纯文本形式存储表格数据的表示方式.JSON也可以表示一二维数据.在网络信息传输中,可能需要统一表示方式,因 ...
- Nginx 常用模块
Nginx 常用模块 1. ngx_http_autoindex_module # ngx_http_autoindex_module模块处理以斜杠字符(' / ')结尾的请求,并生成一个目录列表. ...
- SPARQL入门(一)SPARQL简介与简单使用
知识图谱(Knowledge Graph)是当前互联网最炙手可热的技术之一,它的典型应用场景就是搜索引擎,比如Google搜索,百度搜索.我们在百度搜索中输入问题"中国银行的总部在哪&q ...
- Thymeleaf实现页面静态化
如果用户所有的请求,都需要Thyleaf渲染后直接返回给用户,后台就存在大量的查询操作,数据库的压力就会骤然上升,请求的时间就会延长,带来极不好用户体验,现在市面上流行的就是页面的静态化处理,下面就来 ...
- Docker安装ELK
1.下载elk docker pull sebp/elk 2.启动elk //Elasticsearch至少需要单独2G的内存 //增加了一个volume绑定,以免重启container以后ES的数据 ...