无忧启动论坛
标题:
vbs的ImpersonationLevel=impersonate和=3的区别
[打印本页]
作者:
yjqd
时间:
2021-1-21 20:28
标题:
vbs的ImpersonationLevel=impersonate和=3的区别
本帖最后由 yjqd 于 2021-1-21 20:30 编辑
vbs的ImpersonationLevel=impersonate和=3的区别
下面代码运行正常
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer(".", "root\cimv2")
objWMIService.Security_.ImpersonationLevel = impersonate
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
For each objDisk in colDisks
Wscript.Echo "DeviceID: " & vbTab & objDisk.DeviceID & vbNewLine & _
"FreeSpace: " & vbTab & objDisk.FreeSpace
Next
如果红色加粗语句
改为
o
bjWMIService.Security_.ImpersonationLevel =
3,运行就会报错
有的语句是这样写的,运行正常:
Set objWMIService = GetObject("WinMgmts:{
impersonationLevel=
impersonate
}" & "\\.\root/cimv2")
欢迎光临 无忧启动论坛 (http://wuyou.net/)
Powered by Discuz! X3.3