我需要检查执行脚本的用户是否在机器上具有管理权限.
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 管理权限的最佳方法
发布评论