以下の非常に単純なスクリプトがあります
Imports System.Management
Imports System
Module Module1
Dim watcher As ManagementEventWatcher
Sub Main()
Dim monitoredProcess = "iexplore.exe"
Dim query As WqlEventQuery = New WqlEventQuery("__InstanceCreationEvent", New TimeSpan(0, 0, 1), "TargetInstance isa ""Win32_Process"" And TargetInstance.Name = """ & monitoredProcess & """")
watcher = New ManagementEventWatcher()
watcher.Query = query
watcher.Start()
watcher.WaitForNextEvent()
For Each p As Process In Process.GetProcessesByName("iexplore")
p.Kill()
Next
Process.Start(New System.Diagnostics.ProcessStartInfo("Chrome", "http://google.com"))
End Sub
End Module
ieウィンドウが開いたときに監視し、閉じて代わりにchromeを実行する必要があります。これは最初はうまく機能しますが、完了すると次のエラーでクラッシュします
An unhandled exception of type 'System.Runtime.InteropServices.InvalidComObjectException' occurred in System.Management.dll
Additional information: COM object that has been separated from its underlying RCW cannot be used.
コムが分離しないようにするにはどうすればよいですか? プログラムを Windows で開始し、常に実行し続けたいと思います。
ありがとう