本文整理汇总了C#中System.Management.ManagementOperationObserver类的典型用法代码示例。如果您正苦于以下问题:C# ManagementOperationObserver类的具体用法?C# ManagementOperationObserver怎么用?C# ManagementOperationObserver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ManagementOperationObserver类属于System.Management命名空间,在下文中一共展示了ManagementOperationObserver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UsbDeviceEvent
public UsbDeviceEvent()
{
this.creationEventWatcher = (ManagementEventWatcher)null;
ManagementOperationObserver operationObserver = new ManagementOperationObserver();
ManagementScope scope = new ManagementScope("root\\CIMV2");
scope.Options.EnablePrivileges = true;
try
{
WqlEventQuery wqlEventQuery = new WqlEventQuery();
wqlEventQuery.EventClassName = "__InstanceCreationEvent";
wqlEventQuery.WithinInterval = new TimeSpan(0, 0, 3);
wqlEventQuery.Condition = "TargetInstance ISA 'Win32_USBControllerDevice'";
Console.WriteLine(wqlEventQuery.QueryString);
this.creationEventWatcher = new ManagementEventWatcher(scope, (EventQuery)wqlEventQuery);
this.creationEventWatcher.EventArrived += new EventArrivedEventHandler(this.creationEventWatcher_EventArrived);
this.creationEventWatcher.Start();
wqlEventQuery.EventClassName = "__InstanceDeletionEvent";
wqlEventQuery.WithinInterval = new TimeSpan(0, 0, 3);
wqlEventQuery.Condition = "TargetInstance ISA 'Win32_USBControllerdevice'";
Console.WriteLine(wqlEventQuery.QueryString);
this.deletionEventWatcher = new ManagementEventWatcher(scope, (EventQuery)wqlEventQuery);
this.deletionEventWatcher.EventArrived += new EventArrivedEventHandler(this.deletionEventWatcher_EventArrived);
this.deletionEventWatcher.Start();
}
catch
{
this.Dispose();
}
}
示例2: findPorts
private void findPorts()
{
try
{
comboBox_Ports.Items.Clear();
serialItems.Items.Clear();
ManagementObjectSearcher searcher = new ManagementObjectSearcher( new SelectQuery("WIN32_SerialPort"));
ManagementOperationObserver results = new ManagementOperationObserver();
results.ObjectReady += new ObjectReadyEventHandler(this.NewObject);
results.Completed += new CompletedEventHandler(this.Done);
// Get availble port names asynchronously
searcher.Get(results);
while (!this.Completed)
{
System.Threading.Thread.Sleep(1000);
}
this.Reset();
}
catch (ManagementException e)
{
MessageBox.Show("Failed to run query: " + e.Message);
throw;
}
foreach (object port in serialItems.Items)
{
comboBox_Ports.Items.Add(port);
}
}
示例3: WmiEventSink
protected WmiEventSink(ManagementOperationObserver watcher, object context, ManagementScope scope, string path, string className)
{
try
{
this.context = context;
this.watcher = watcher;
this.className = className;
this.isLocal = false;
if (path != null)
{
this.path = new ManagementPath(path);
if (string.Compare(this.path.Server, ".", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(this.path.Server, Environment.MachineName, StringComparison.OrdinalIgnoreCase) == 0)
{
this.isLocal = true;
}
}
if (scope != null)
{
this.scope = scope.Clone();
if (path == null && (string.Compare(this.scope.Path.Server, ".", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(this.scope.Path.Server, Environment.MachineName, StringComparison.OrdinalIgnoreCase) == 0))
{
this.isLocal = true;
}
}
WmiNetUtilsHelper.GetDemultiplexedStub_f(this, this.isLocal, out this.stub);
this.hash = Interlocked.Increment(ref WmiEventSink.s_hash);
}
catch
{
}
}
示例4: WmiAsyncCmdletHelper
/// <summary>
/// Internal Constructor
/// </summary>
/// <param name="childJob">Job associated with this operation</param>
/// <param name="wmiObject">object associated with this operation</param>
/// <param name="computerName"> computer on which the operation is invoked </param>
/// <param name="results"> sink to get wmi objects </param>
internal WmiAsyncCmdletHelper(PSWmiChildJob childJob, Cmdlet wmiObject, string computerName, ManagementOperationObserver results)
{
_wmiObject = wmiObject;
_computerName = computerName;
_results = results;
this.State = WmiState.NotStarted;
_job = childJob;
}
示例5: Create
/// <summary>Creates a new process</summary>>
/// <param name="commandLine">Command line to execute</param>
/// <param name="currentDirectory">Current drive and directory for the child process</param>
/// <param name="processStartupInformation">The startup configuration of a Windows process</param>
/// <param name="processId">Global process identifier that can be used to identify a process</param>
public void Create(string commandLine, string currentDirectory, Win32_ProcessStartup processStartupInformation,ref uint processId)
{
object[] methodArgs = { commandLine, currentDirectory, processStartupInformation, processId };
ManagementOperationObserver observer = new ManagementOperationObserver();
this._mc.InvokeMethod(observer, "Create", methodArgs);
processId = Convert.ToUInt32(methodArgs[3]);
}
示例6: KillProcess
/// <summary>
/// Kills the process.
/// </summary>
/// <param name="machineName">Name of the machine.</param>
/// <param name="serviceObj">The service obj.</param>
/// <param name="observer">The observer.</param>
public static void KillProcess(string machineName, ManagementObject serviceObj, ManagementOperationObserver observer)
{
string str = String.Empty;
foreach (var prop in serviceObj.Properties)
{
str += String.Format("{0} - {1}\r\n", prop.Name, prop.Value);
}
var processObj = GetProcess(machineName, serviceObj["ProcessId"].ToString());
processObj.InvokeMethod(observer, "Terminate", null);
}
示例7: GetWmiGetEventSink
internal static WmiGetEventSink GetWmiGetEventSink(ManagementOperationObserver watcher, object context, ManagementScope scope, ManagementObject managementObject)
{
if (MTAHelper.IsNoContextMTA())
{
return new WmiGetEventSink(watcher, context, scope, managementObject);
}
watcherParameter = watcher;
contextParameter = context;
scopeParameter = scope;
managementObjectParameter = managementObject;
new ThreadDispatch(new ThreadDispatch.ThreadWorkerMethod(WmiGetEventSink.HackToCreateWmiGetEventSink)).Start();
return wmiGetEventSinkNew;
}
示例8: GetWmiEventSink
internal static WmiEventSink GetWmiEventSink(ManagementOperationObserver watcher, object context, ManagementScope scope, string path, string className)
{
if (MTAHelper.IsNoContextMTA())
{
return new WmiEventSink(watcher, context, scope, path, className);
}
watcherParameter = watcher;
contextParameter = context;
scopeParameter = scope;
pathParameter = path;
classNameParameter = className;
new ThreadDispatch(new ThreadDispatch.ThreadWorkerMethod(WmiEventSink.HackToCreateWmiEventSink)).Start();
return wmiEventSinkNew;
}
示例9: Factory
private IObservable<ManagementBaseObject> Factory(ManagementClass mc)
{
var src = new ReplaySubject<ManagementBaseObject>();
var ob = new ManagementOperationObserver();
Observable.FromEventPattern<ObjectReadyEventHandler, ObjectReadyEventArgs>(
h => h.Invoke,
h => ob.ObjectReady += h,
h => ob.ObjectReady -= h
).Subscribe(obj => src.OnNext(obj.EventArgs.NewObject));
Observable.FromEventPattern<CompletedEventHandler, CompletedEventArgs>(
h => h.Invoke,
h => ob.Completed += h,
h => ob.Completed -= h
).Subscribe(_ => src.OnCompleted());
mc.GetInstances(ob);
return src.AsObservable();
}
示例10: PSWmiChildJob
internal PSWmiChildJob(Cmdlet cmds, string computerName, ThrottleManager throttleManager) : base(null, null)
{
this.syncObject = new object();
this.statusMessage = "test";
base.UsesResultsCollection = true;
this.computerName = computerName;
this.throttleManager = throttleManager;
this.wmiSinkArray = new ArrayList();
ManagementOperationObserver managementOperationObserver = new ManagementOperationObserver();
this.wmiSinkArray.Add(managementOperationObserver);
PSWmiChildJob pSWmiChildJob = this;
pSWmiChildJob.sinkCompleted = pSWmiChildJob.sinkCompleted + 1;
managementOperationObserver.ObjectReady += new ObjectReadyEventHandler(this.NewObject);
managementOperationObserver.Completed += new CompletedEventHandler(this.JobDone);
this.helper = new WmiAsyncCmdletHelper(this, cmds, computerName, managementOperationObserver);
this.helper.WmiOperationState += new EventHandler<WmiJobStateEventArgs>(this.HandleWMIState);
this.helper.ShutdownComplete += new EventHandler<EventArgs>(this.JobDoneForWin32Shutdown);
base.SetJobState(JobState.NotStarted);
IThrottleOperation throttleOperation = this.helper;
throttleOperation.OperationComplete += new EventHandler<OperationStateEventArgs>(this.HandleOperationComplete);
throttleManager.ThrottleComplete += new EventHandler<EventArgs>(this.HandleThrottleComplete);
throttleManager.AddOperation(throttleOperation);
}
示例11: GetRelationships
public void GetRelationships (ManagementOperationObserver watcher, string relationshipClass)
{
throw new NotImplementedException ();
}
示例12: GetRelated
public void GetRelated (ManagementOperationObserver watcher)
{
throw new NotImplementedException ();
}
示例13: PSWmiChildJob
/// <summary>
/// Internal constructor for initializing WMI jobs, where WMI command is executed a variable
/// number of times.
/// </summary>
internal PSWmiChildJob(Cmdlet cmds, string computerName, ThrottleManager throttleManager, int count)
: base(null, null)
{
UsesResultsCollection = true;
Location = computerName;
_throttleManager = throttleManager;
_wmiSinkArray = new ArrayList();
ManagementOperationObserver wmiSink = new ManagementOperationObserver();
_wmiSinkArray.Add(wmiSink);
_sinkCompleted += count;
wmiSink.ObjectReady += new ObjectReadyEventHandler(this.NewObject);
wmiSink.Completed += new CompletedEventHandler(this.JobDone);
_helper = new WmiAsyncCmdletHelper(this, cmds, computerName, wmiSink, count);
_helper.WmiOperationState += new EventHandler<WmiJobStateEventArgs>(HandleWMIState);
_helper.ShutdownComplete += new EventHandler<EventArgs>(JobDoneForWin32Shutdown);
SetJobState(JobState.NotStarted);
IThrottleOperation operation = _helper;
operation.OperationComplete += new EventHandler<OperationStateEventArgs>(HandleOperationComplete);
throttleManager.ThrottleComplete += new EventHandler<EventArgs>(HandleThrottleComplete);
throttleManager.AddOperation(operation);
}
示例14: SetupDriveWatcher
void SetupDriveWatcher()
{
try
{
ManagementEventWatcher w = null;
WqlEventQuery q;
ManagementOperationObserver observer = new ManagementOperationObserver();
// Bind to local machine
ManagementScope scope = new ManagementScope("root\\CIMV2");
scope.Options.EnablePrivileges = true; //sets required privilege
q = new WqlEventQuery();
q.EventClassName = "__InstanceOperationEvent";
q.WithinInterval = new TimeSpan(0, 0, 3);
q.Condition = @"TargetInstance ISA 'Win32_DiskDrive' ";
//Console.WriteLine(q.QueryString);
w = new ManagementEventWatcher(scope, q);
w.EventArrived += new EventArrivedEventHandler(UsbEventArrived);
w.Start();
// Console.ReadLine(); // block main thread for test purposes
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
示例15: InvokeMethod
public void InvokeMethod (ManagementOperationObserver watcher,
string methodName,
ManagementBaseObject inParameters,
InvokeMethodOptions options)
{
throw new NotImplementedException ();
}