En bekendt smed dette script til mig igår:
men kan ikke rigtig få det til at spille
Dim oWMI : Set oWMI = GetObject("winmgmts://./root/cimv2")
'Create a callback method name and assign the events to it
Dim myEventSink : Set myEventSink = WScript.CreateObject("WbemScripting.SWbemSink","ProcessDeletion_")
'Start the async operation and send the events to the "ProcessDeletion_" correct event callback methods
oWMI.ExecNotificationQueryAsync myEventSink, "SELECT * FROM __InstanceDeletionEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'"
'''<summary>A call back for events raised by the ExecNotificationQueryAsync method</summary>
'''<param name="oObject">An SWbemObject object</param>
'''<param name="oAsyncContext">An SWbemNamedValueSet object that is passed to the original asynchronous call</param>
'''<remarks>This method needs to be 'Public' in order to be called from the ExecNotificationQueryAsync method</remarks>
Public Sub ProcessDeletion_OnObjectReady(ByRef oObject, ByRef oAsyncContext)
Call CheckProcesses(".", Array("iexplore.exe"))
End Sub
'''<summary>Finds the count of the specified processes</summary>
'''<param name="sComputer">The local or remote endpoint to connect to</param>
'''<param name="aParams">An array of processes that you want to find</param>
Private Sub CheckProcesses(ByVal sComputer, ByRef aParams)
On Error Resume Next
Dim oWMI : Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & sComputer & "/root/cimv2")
Dim sQuery : sQuery = "SELECT * FROM Win32_Process WHERE"
Dim oProcessCollection, oIE
For i=0 To UBound(aParams)
'Yes, this isn't a good way to use string concatenation
If i = 0 Then
sQuery = sQuery & " Name='" & aParams(i) & "'"
Else
sQuery = sQuery & " OR Name='" & aParams(i) & "'"
End If
Next
Set oProcessCollection = oWMI.ExecQuery(sQuery)
If oProcessCollection.Count = 0 Then
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True
End If
End Sub