用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 ...
随机推荐
- iPhone 启动页尺寸
iPhone 启动页尺寸 4 640*960 5 640*1136 6 750*1334 6p 1242*2208
- OpenStack与ZStack深度对比:架构、部署、计算、运维监控等
摘要 OpenStack从2010年开源至今,已经走过9个年头,其正在进入主流企业市场,但该项目依然面临较难部署和管理的老问题.有一点是毫无疑问的,那就是OpenStack保持着高速增长的态势,超过5 ...
- Hibernate session.save()实体类,主键增长问题
实体类如下: package com.wondersgroup.test.entity; import java.io.Serializable; import javax.persisten ...
- IT兄弟连 HTML5教程 CSS3揭秘 CSS常见的样式属性和值4
6 鼠标光标属性 在网页中默认的鼠标指针只有两种,一种是最普通的箭头,另一种是当移动到链接上时出现的“小手”.但现在越来越多的网页都使用了CSS鼠标指针技术,当将鼠标移动到链接上时,可以看到多种不同 ...
- 【Java基础】正则表达式
目录 正则表达式 什么正则表达式 普通字符 预定义字符 特殊字符 数量限定字符 定位字符 选择符和分组 反向引用 预搜索 运算符的优先级 常用正则 附录 正则表达式 本文的大部分内容转载自正则表达式从 ...
- 单个div元素实现双边框
昨天被问到一个很有意思的问题,单个div元素怎么实现双边框,当时脑子懵了一下,然后就回答出来用伪元素,别的实在是想不起来了,所以在此总结一下子防止以后再被问到 总结了一下大约有以下几种方案: 伪元素实 ...
- Java - java概述
简介: JAVA是一门面向对象的编程语言 1995有sun公司发布 java程序执行流程: xxxjava源文件, 经过编译器编译 产生字节码文件 字节码交给解释器 解释成当前平台的本地机器指令 名词 ...
- javaWeb技术第二篇之CSS、事件和案例
<!--内联式 CSS (层叠样式表) 编辑 层叠样式表(英文全称:Cascading Style Sheets) CSS不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式 ...
- C#中增量类功能的方式之 继承与扩展
之前一次公司培训的时候,将它记录下来,https://www.cnblogs.com/AlvinLee/p/10180536.html这个博客上面比较全面. 1.扩展方法 扩展方法是一种特殊的静态方法 ...
- CSS学习笔记-盒子阴影及文字阴影
盒子阴影: 1.格式: box-shadow:h-shadow v-shadow blur spread color insert; box-shadow:水平偏移 ...