Re: Help a newbie with this VBScript

From: Jonas Sackerud (jonas.sackerud_at_seaflex.net)
Date: 04/02/04


Date: Fri, 2 Apr 2004 08:00:48 +0200

I can't thank you enough Stivie. This saves me both time and money. Good
work!

"Stivie S." <stefan.suesser@computacenter.com> skrev i meddelandet
news:B09C5EEC-E24D-4B25-A9A8-6CA04FCEDFEE@microsoft.com...
> Hi Jonas,
>
> you can easily modify the script to run indefinitely - until you terminate
it manually or log off. Just put a "DO...LOOP" statement around the line
that gathers the event. Here's how:
>
> strComputer = "."
> IomegaModelID = "IC35L090 AVV207-0 USB Device"
> Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
> Set Events =
GetObject("winmgmts:\\.\root\cimv2").ExecNotificationQuery("SELECT
TargetInstance.Model " _
> & "FROM __InstanceCreationEvent WITHIN 5 " _
> & "WHERE TargetInstance ISA 'Win32_DiskDrive' and " _
> & "TargetInstance.InterfaceType='USB' and ") _
> & "TargetInstance.Model='" & IomegaModelID & "'")
>
>
> DO
> Set DiskEvent = Events.NextEvent
> Wscript.Echo "USB drive connected: " &
DiskEvent.TargetInstance.Model
> LOOP
>
> You can read a nice description of scripting WMI events in the Windows
2000 Scripting Guide on TechNet. Here is the link to the WMI event
documentation:
>
http://www.microsoft.com/resources/documentation/windows/2000/server/scriptguide/en-us/sas_wmi_kzcp.mspx
>
> When you want to run this WMI event consumer all the time, then I would
recommend that you install a permanent event consumer. The MSDN library
contains nice documentation how you create and compile a permanent event
consumer using the "ActiveScriptEventConsumer". In short: you create a MOF
file that contains the code for your event consumer, then compile this MOF
using "mofcomp.exe". By this, the event consumer will be compiled in your
WMI repository so that you do not have to start the script yourself. Here's
the link to the MSDN documentation:
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/running_a_script_based_on_an_event.asp
>
> Hope this helps...