了解用户是否具有 VBScript 管理权限的最佳方法 [英] Best way to know if a user has administrative privileges from a VBScript

查看:38
本文介绍了了解用户是否具有 VBScript 管理权限的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查执行脚本的用户是否在机器上具有管理权限.

I need to check whether the user executing the script has administrative privileges on the machine.

我已经指定了执行脚本的用户,因为该脚本可以由一个用户执行,而不是使用类似于Runas"的东西.

I have specified the user executing the script because the script could have been executed with a user other than the logged on using something similar to "Runas".

@Javier:这两种解决方案都适用于安装了英文版 Windows 的 PC,但如果安装的语言不同,则无法使用.这是因为管理员组不存在,名称不同,例如西班牙语.我需要该解决方案适用于所有配置.

@Javier: Both solutions work in a PC with an English version of Windows installed but not if the installed is in different language. This is because the Administrators group doesn't exist, the name is different for instance in Spanish. I need the solution to work in all configurations.

推荐答案

如果你想查看登录用户是否是管理员,可以使用脚本

You can use script if you want to see if the logged on user is an administrator

Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
strUser = objNetwork.UserName

isAdministrator = false

Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
For Each objUser in objGroup.Members
    If objUser.Name = strUser Then
        isAdministrator = true        
    End If
Next

If isAdministrator Then
    Wscript.Echo strUser & " is a local administrator."
Else
    Wscript.Echo strUser & " is not a local administrator."
End If

当脚本使用Runas"运行时,我不确定如何处理它.

I am not sure how to handle it when the script is run with "Runas" I am afraid.

这篇关于了解用户是否具有 VBScript 管理权限的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆