本文整理汇总了C#中System.Management.ManagementOperationObserver类的典型用法代码示例。如果您正苦于以下问题:C# ManagementOperationObserver类的具体用法?C# ManagementOperationObserver怎么用?C# ManagementOperationObserver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ManagementOperationObserver类属于System.Management命名空间,在下文中一共展示了ManagementOperationObserver类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
}
开发者ID:kaaLabs15,项目名称:LoRa,代码行数:29,代码来源:UsbDeviceEvent.cs
示例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);
}
}
开发者ID:JacobD10,项目名称:ASAR,代码行数:33,代码来源:formConnect.cs
示例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
{
}
}
开发者ID:nickchal,项目名称:pash,代码行数:31,代码来源:WmiEventSink.cs
示例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;
}
开发者ID:dfinke,项目名称:powershell,代码行数:15,代码来源:WMIHelper.cs
示例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]);
}
开发者ID:windygu,项目名称:asxinyunet,代码行数:13,代码来源:Win32_Process.cs
示例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);
}
开发者ID:JordanZaerr,项目名称:ServiceWatcher,代码行数:16,代码来源:Operations.cs
示例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;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:WmiGetEventSink.cs
示例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;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:14,代码来源:WmiEventSink.cs
示例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();
}
开发者ID:s-nlf-fh,项目名称:SerialPortMonitor,代码行数:20,代码来源:Edge.cs
示例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);
}
开发者ID:nickchal,项目名称:pash,代码行数:23,代码来源:PSWmiChildJob.cs
示例11: GetRelationships
public void GetRelationships (ManagementOperationObserver watcher, string relationshipClass)
{
throw new NotImplementedException ();
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:4,代码来源:ManagementObject.cs
示例12: GetRelated
public void GetRelated (ManagementOperationObserver watcher)
{
throw new NotImplementedException ();
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:4,代码来源:ManagementObject.cs
示例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);
}
开发者ID:dfinke,项目名称:powershell,代码行数:25,代码来源:WMIHelper.cs
示例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);
}
}
开发者ID:anndream,项目名称:anpr-1,代码行数:28,代码来源:DriveManager.cs
示例15: InvokeMethod
public void InvokeMethod (ManagementOperationObserver watcher,
string methodName,
ManagementBaseObject inParameters,
InvokeMethodOptions options)
{
throw new NotImplementedException ();
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:ManagementObject.cs
示例16: GetEventLogItemMessages
private void GetEventLogItemMessages(string machinename, string logname)
{
if (_eventMessagesObserver == null)
{
ManagementScope messageScope = new ManagementScope(
GetStandardPath(machinename)
);
messageScope.Connect();
StringBuilder query = new StringBuilder();
query.Append("select Message, InsertionStrings, RecordNumber from Win32_NTLogEvent where LogFile ='");
query.Append(logname.Replace("'", "''"));
query.Append("'");
System.Management.ObjectQuery objectQuery = new System.Management.ObjectQuery(
query.ToString()
);
EnumerationOptions objectQueryOptions = new EnumerationOptions();
objectQueryOptions.BlockSize = 100000;
ManagementObjectSearcher objectSearcher = new ManagementObjectSearcher(messageScope, objectQuery);
_eventMessagesObserver = new ManagementOperationObserver();
_eventMessagesObserver.ObjectReady += new ObjectReadyEventHandler(OnEventLogEntryReady);
_eventMessagesObserver.Completed += new CompletedEventHandler(OnEventLogEntryCompleted);
objectSearcher.Get(_eventMessagesObserver);
}
}
开发者ID:efvb,项目名称:snaketail-net,代码行数:30,代码来源:EventLogForm.cs
示例17: CopyTo
public void CopyTo (ManagementOperationObserver watcher, ManagementPath path)
{
throw new NotImplementedException ();
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:4,代码来源:ManagementObject.cs
示例18: Put
public void Put (ManagementOperationObserver watcher, PutOptions options)
{
throw new NotImplementedException ();
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:4,代码来源:ManagementObject.cs
示例19: CreateProcess
/// <summary>
/// Invoke method 'Create' on local or remote machine
/// </summary>
/// <param name="stringCommandLine"></param>
private void CreateProcess(string stringCommandLine)
{
//Set up a handler for the asynchronous callback
ManagementOperationObserver observer = new ManagementOperationObserver();
completionHandler.MyHandler completionHandlerObj = new completionHandler.MyHandler();
observer.ObjectReady += new ObjectReadyEventHandler(completionHandlerObj.Done);
string stringMachineName = "";
//Connect to the remote computer
ConnectionOptions co = new ConnectionOptions();
if (radioMachine.Checked == true)
{
stringMachineName = "localhost";
}
else
{
stringMachineName = textIP.Text;
}
if (stringMachineName.Trim().Length == 0)
{
MessageBox.Show("Must enter machine IP address or name.");
return;
}
//get user and password
if (textUserID.Text.Trim().Length > 0)
{
co.Username = textUserID.Text;
co.Password = textPassword.Text;
}
//Point to machine
System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\" + stringMachineName + "\\root\\cimv2", co);
//get process path
ManagementPath path = new ManagementPath( "Win32_Process");
//Get the object on which the method will be invoked
ManagementClass processClass = new ManagementClass(ms,path,null);
//Status
updateStatus("Create process " + stringCommandLine + ".");
//Create an array containing all arguments for the method
object[] methodArgs = {stringCommandLine, null, null, 0};
//Execute the method
processClass.InvokeMethod (observer, "Create", methodArgs);
//wait until invoke method is complete or 5 sec timeout
int intCount = 0;
while (!completionHandlerObj.IsComplete)
{
if (intCount > 10)
{
MessageBox.Show("Create process timed out.", "Terminate Process Status");
break;
}
//wait 1/2 sec.
System.Threading.Thread.Sleep(500);
//increment counter
intCount++;
}
if (intCount != 10)
{
//InvokeMethod did not time out
//check for error
if (completionHandlerObj.ReturnObject.Properties["returnValue"].Value.ToString() == "0")
{
//refresh process list
this.Refresh();
}
else
{
MessageBox.Show("Error creating new process.", "Create New Process");
}
}
//Status
updateStatus("Ready");
this.Update();
}
开发者ID:priceLiu,项目名称:ServerController,代码行数:90,代码来源:Process.cs
示例20: OnStart
protected override void OnStart(string[] args)
{
WMIEvent we = new WMIEvent();
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
try {
q = new WqlEventQuery();
q.EventClassName = "__InstanceOperationEvent";
q.WithinInterval = new TimeSpan(0, 0, 3);
q.Condition = @
"TargetInstance ISA 'Win32_DiskDrive' ";
//EventLog es una forma de escribir lo que está pasando en
//el visor de sucesos de windows
EventLog.WriteEntry(q.QueryString);
w = new ManagementEventWatcher(q);
w.EventArrived += new
EventArrivedEventHandler(we.UsbEventArrived);
w.Start();
} catch (Exception e) {
EventLog.WriteEntry(e.Message);
}
}
开发者ID:wilfredor,项目名称:USB_blacklist,代码行数:29,代码来源:main.cs
注:本文中的System.Management.ManagementOperationObserver类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论