Python Gurus,
Is it possible to write python WMI event consumer using event handler
rather than polling WMI?
I got the equivalent C# code snippet from
using System;
using System.Manageme nt;
using System.Collecti ons;
class WSMonitor
{
bool pleaseContinue = true;
public void doit()
{
try
{
int processId =
System.Diagnost ics.Process.Get CurrentProcess( ).Id;
int workingSet = 30000000;
string wqlQuery = String.Format(
@"SELECT * FROM __InstanceModif icationEvent WITHIN 1
WHERE TargetInstance ISA 'Win32_Process' AND
TargetInstance. ProcessId = {0} AND
TargetInstance. WorkingSetSize >= {1} AND
PreviousInstanc e.WorkingSetSiz e < {2} ",
processId, workingSet, workingSet);
WqlEventQuery query = new WqlEventQuery(w qlQuery);
ManagementEvent Watcher watcher =
new ManagementEvent Watcher(query);
watcher.EventAr rived +=
new EventArrivedEve ntHandler(onEve nt);
watcher.Start() ;
ArrayList array = new ArrayList();
for (int i = 0; pleaseContinue; ++i)
{
array.Add(1);
if (i % 1000 == 0)
System.Threadin g.Thread.Sleep( 1);
}
watcher.Stop();
}
catch (ManagementExce ption e)
{
Console.WriteLi ne("Management exception: " + e);
}
}
public void onEvent(object sender, EventArrivedEve ntArgs e)
{
pleaseContinue = false;
Console.WriteLi ne("You're a big boy now!");
}
}
Thanks
Is it possible to write python WMI event consumer using event handler
rather than polling WMI?
I got the equivalent C# code snippet from
using System;
using System.Manageme nt;
using System.Collecti ons;
class WSMonitor
{
bool pleaseContinue = true;
public void doit()
{
try
{
int processId =
System.Diagnost ics.Process.Get CurrentProcess( ).Id;
int workingSet = 30000000;
string wqlQuery = String.Format(
@"SELECT * FROM __InstanceModif icationEvent WITHIN 1
WHERE TargetInstance ISA 'Win32_Process' AND
TargetInstance. ProcessId = {0} AND
TargetInstance. WorkingSetSize >= {1} AND
PreviousInstanc e.WorkingSetSiz e < {2} ",
processId, workingSet, workingSet);
WqlEventQuery query = new WqlEventQuery(w qlQuery);
ManagementEvent Watcher watcher =
new ManagementEvent Watcher(query);
watcher.EventAr rived +=
new EventArrivedEve ntHandler(onEve nt);
watcher.Start() ;
ArrayList array = new ArrayList();
for (int i = 0; pleaseContinue; ++i)
{
array.Add(1);
if (i % 1000 == 0)
System.Threadin g.Thread.Sleep( 1);
}
watcher.Stop();
}
catch (ManagementExce ption e)
{
Console.WriteLi ne("Management exception: " + e);
}
}
public void onEvent(object sender, EventArrivedEve ntArgs e)
{
pleaseContinue = false;
Console.WriteLi ne("You're a big boy now!");
}
}
Thanks