获取当前已启用的值通过VBS

huangapple go评论67阅读模式
英文:

UWF: get CurrentEnabled value via VBS

问题

我正在尝试创建一个简单的VBScript脚本来获取UWF状态:

Set objWMIService = GetObject("winmgmts:\\.\root\StandardCimv2\embedded:UWF_Filter") 
WScript.Echo objWMIService.CurrentEnabled

输出是null,即使我以管理员身份运行也是如此。

英文:

I'm trying to create a simple vbs script to get UWF status:

Set objWMIService = GetObject("winmgmts:\\.\root\StandardCimv2\embedded:UWF_Filter") 
WScript.Echo objWMIService.CurrentEnabled

The output is null even if I run it as administrator.

答案1

得分: 2

我找到了解决方案:我需要查找UWF_Filter的实例。这是适用于UWF_filter的工作代码

Set uwfFilters = GetObject("winmgmts:\\.\root\StandardCimv2\embedded:UWF_Filter") 
Set oInstances = uwfFilters.instances_()

For Each oInstance In oInstances
	if oInstance.CurrentEnabled and oInstance.NextEnabled then
		Echo "Enabled"
	elseif oInstance.CurrentEnabled and not oInstance.NextEnabled then
		Echo "Enabled (will be disabled)"
	elseif not oInstance.CurrentEnabled and oInstance.NextEnabled then
		Echo "Disabled (will be enabled)"
	else
		Echo "Disabled"
	end if
Next

奖励点: 此脚本用于 BGInfo,因此您需要将 Wscript.Echo 替换为 Echo

英文:

I found the solution: I've to look for the instances of UWF_Filter. This is the working code for UWF_filter

Set uwfFilters = GetObject("winmgmts:\\.\root\StandardCimv2\embedded:UWF_Filter") 
Set oInstances = uwfFilters.instances_()

For Each oInstance In oInstances
	if oInstance.CurrentEnabled and oInstance.NextEnabled then
		Wscript.Echo "Enabled"
	elseif oInstance.CurrentEnabled and not oInstance.NextEnabled then
		Wscript.Echo "Enabled (will be disabled)"
	elseif not oInstance.CurrentEnabled and oInstance.NextEnabled then
		Wscript.Echo "Disabled (will be enabled)"
	else
		Wscript.Echo "Disabled"
	end if
Next

Bonus point: this script is intended for BGInfo, so you need to replace Wscript.Echo with Echo.

huangapple
  • 本文由 发表于 2023年5月11日 15:11:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76224967.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定