Tech Support Forum banner

Wscript and WMI

1348 Views 1 Reply 1 Participant Last post by  BlackMan890
Hi guys :)

i am making a scriptfor myself, where somethling like this happens:

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecNotificationQuery("SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_Process'")

Do
	Set objNewProcess = colProcesses.NextEvent
	If objNewProcess.TargetInstance.Name = "WINWORD.EXE" THEN
		Do While ObjNewProcess Is Open
			'Do something
		Loop
	End If
Loop
This is something i found on the internet:

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecNotificationQuery("SELECT * FROM __InstanceDeletionEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.Name = 'notepad.exe'")

Set objNewProcess = colProcess.NextEvent

'Do something
However the problem with the code above is that it stops at colProcess.NextEvent, while i want it to loop UNTIL it is closed.

Is it possible to do something like that?

Let me know.


P.S.
I am new here and i must say this is a very nice place :D
See less See more
Status
Not open for further replies.
1 - 2 of 2 Posts
Never mind, found the answer myself after many search in msdn.microsoft.com

thanks anyway.
1 - 2 of 2 Posts
Status
Not open for further replies.
Top