在 VBScript 中从 SID 字符串获取域用户名的方法
最近,我正在用纯 VBScript 编写一个系统管理脚本,其要求是它必须是可移植的,不需要安装额外的软件。
我有 SID 的字符串版本(例如“S-1-5-21-123456789...”)并且想要获取用户名和域名。
尝试通过 WMI 执行此操作会失败,部分原因是它必须在域控制器上搜索 10,000 个对象。
但也许可以通过以下方式之一完成:
if 我们可以假设 .NETfx 2.0 已安装(我真的希望避免这种情况,因为它不完全可移植),通过 System.Security.Principal (C# 中的示例:
using System.Security.Principal; string account = new SecurityIdentifier(stringSid).Translate(typeof(NTAccount)).ToString();
)
对我有什么建议吗?
Recently I was working on a system administration script in pure VBScript where the requirements are that it must be portable with no additional software installation needed.
I have the string version of the SID (e.g. "S-1-5-21-123456789...") and want to get the username and domain name.
Attempts to do this via WMI fail in part because of the 10,000's of objects it has to search through on the domain controllers.
But perhaps it can be done one of these ways:
if we can assume that the .NETfx 2.0 is installed (which I would really prefer to avoid, since it will not be totally portable), via the System.Security.Principal (example in C#:
using System.Security.Principal; string account = new SecurityIdentifier(stringSid).Translate(typeof(NTAccount)).ToString();
)
Any suggestions for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在多域林中建立组成员身份。
Building group membership in multidomain forest.
您可以简单地使用 ADSI 绑定到 SID。在 VBScript 中,会是这样的:
You can simply bind with ADSI to the SID. In VBScript that would be something like this:
我自己找到的最好方法是查询 WMI,如下所示:
如您所见,我必须添加一些错误处理程序——呃,而不是——“盲目地跳过错误”,因为查询并不总是成功(并且可能存在一些不易测试的潜在原因)。
The best method I have found on my own is querying WMI, like this:
As you can see I had to add some error handli--er, rather--"skipping blindly over errors", because the query doesn't always succeed (and there could be a handful of potential causes that aren't easy to test for).