使用 VBScript 获取 Win32_Service 安全描述符 [英] Getting Win32_Service security descriptor using VBScript
问题描述
我正在使用 VbScript 来检索 Win32_Service 的安全描述符.我正在使用以下代码:
I am using VbScript for retrieving the securitydescriptor of a Win32_Service. I am using the following code:
SE_DACL_PRESENT = &h4
ACCESS_ALLOWED_ACE_TYPE = &h0
ACCESS_DENIED_ACE_TYPE = &h1
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate, (Security)}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Service")
For Each objPrinter in colInstalledPrinters
Wscript.Echo "Name: " & objPrinter.Name
' Get security descriptor for printer
Return = objPrinter.GetSecurityDescriptor( objSD )
If ( return <> 0 ) Then
WScript.Echo "Could not get security descriptor: " & Return
wscript.Quit Return
End If
' Extract the security descriptor flags
intControlFlags = objSD.ControlFlags
If intControlFlags AND SE_DACL_PRESENT Then
' Get the ACE entries from security descriptor
colACEs = objSD.DACL
For Each objACE in colACEs
' Get all the trustees and determine which have access to printer
WScript.Echo objACE.Trustee.Domain & "\" & objACE.Trustee.Name
If objACE.AceType = ACCESS_ALLOWED_ACE_TYPE Then
WScript.Echo vbTab & "User has access to printer"
ElseIf objACE.AceType = ACCESS_DENIED_ACE_TYPE Then
WScript.Echo vbTab & "User does not have access to the printer"
End If
Next
Else
WScript.Echo "No DACL found in security descriptor"
End If
Next
但是,每次我运行它时,我都会收到一条消息,说结果代码是 -2147023582,而不是定义的错误代码手册.
However, every time I run it I get the message saying the resulting code is -2147023582 something, rather than the error codes defined in the manual.
有人有什么想法吗?我使用的是 Windows 7 专业版 64 位.
Anyone got any ideas? I am using Windows 7 professional 64-bit.
数字是 -2147023582.可能是某种 64 位问题吗?这看起来不像一个无符号整数存储为有符号整数吗?
The number is -2147023582. Could it be some sort of 64-bit issue? doesn't that look like a unsigned integer stored as a signed integer?
(PS:不要介意变量名...我从 msdn 上撕了一个例子).
(PS: don't mind the variablenames... I ripped an example off of msdn).
推荐答案
错误代码 -2147023582 (0x80070522) 表示客户端未持有所需的权限."很可能是 WMI 名字对象中的 Security
权限不够,您需要以管理员身份运行脚本.(至少,当我以管理员身份运行时,您的脚本在 64 位 Vista 上运行良好.)
The error code -2147023582 (0x80070522) means "A required privilege is not held by the client." Most likely, the Security
privilege in the WMI moniker is not enough, and you need to run your script as Administrator. (At least, your script works fine for me on 64-bit Vista when run as admin.)
这篇关于使用 VBScript 获取 Win32_Service 安全描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!