运行 无需 WScript 即可执行

Run Executable Without WScript

我有以下问题:

我计划通过以下方式实现:

约束

我遇到的问题是 ActiveEventScriptConsuemrs 不能使用 Wscript 对象,这意味着我不能 运行 一个 exe:

objShell.Run("C:\MyProgram.exe")

是否有其他方法可以从 vbscript 运行ning 可执行文件,而这可以从 EventConsumer 完成?或者,我是否可以在脚本 运行 使用 VBScript 以外的东西的情况下注册此订阅?

我会在我的登录脚本中包含 Wait,但我不能延迟结束,因为这会导致我的组策略在登录后 运行 5 分钟!

我尝试从 VBS 查看 运行 批处理文件,但这也使用了 WScript

可执行文件正在检查 (Citrix) 会话开始时发生的事情,所以我不能使用常规 windows 登录作为触发器,因为有时用户会登录会话,即使机器本身已经登录了一段时间。

非常感谢任何帮助!

活动订阅码:

$Computername = $env:COMPUTERNAME

$query = @"
SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE TargetInstance ISA 'CIM_DataFile' AND TargetInstance.Name='C:\test\filewatching\tester.txt'
"@
$instanceFilter = ([WMICLASS]"\$Computername\root\subscription:__EventFilter").CreateInstance()
$instanceFilter.QueryLanguage = 'WQL'
$instanceFilter.Query = $query
$instanceFilter.Name = 'EventFilterNameHere'
$instanceFilter.EventNameSpace = 'root/CIMV2'
$result = $instanceFilter.Put()

$script = 
@"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\test\filewatching\Log.log", 8, True)
objFile.WriteLine "1"

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("C:\MyProgran.exe")
Set objShell = Nothing

objFile.WriteLine "2"

objFile.Close
"@
$instanceConsumer = ([wmiclass]"\$Computername\root\subscription:ActiveScriptEventConsumer").CreateInstance()
$instanceConsumer.Name = 'ConsumerNameHere'
$instanceConsumer.ScriptingEngine = 'VBScript'
$instanceConsumer.ScriptFilename = '' 
$instanceConsumer.ScriptText = $script
$instanceConsumer.Put()

[object]$Filter = (Get-WMIObject -Computername $Computername -Namespace root\Subscription -Class __EventFilter | Sort Name)
[object]$Consumer = (Get-WMIObject -Computername $Computername -Namespace root\Subscription -Class __EventConsumer | Sort Name)

$instanceBinding = ([wmiclass]"\$Computername\root\subscription:__FilterToConsumerBinding").CreateInstance()
$instanceBinding.Filter = $Filter
$instanceBinding.Consumer = $Consumer
$instanceBinding.Put()

使用这种类型的事件使用者是不可能的。这是因为 ActiveScriptEventConsumer 不允许除基本消息框外的任何屏幕交互:

Docs

When WMI is run as a service, scripts run by ActiveScriptEventConsumer do not generate screen output. Scripts that use MsgBox do run, but they do not display information on the screen. Running the WMI service as an executable file is not supported, but WMI allows scripts that use the MsgBox function to display output or accept user input. None of the methods provided by the WScript object can be used because ActiveScriptEventConsumer does not use Windows Script Host (WSH).

另一种选择是使用 CSCript,它只使用命令行,但这也不支持可视化 activity(仅命令行),所以为了我的目的,这将不行。