本文整理汇总了C#中System.Management.EnumerationOptions类的典型用法代码示例。如果您正苦于以下问题:C# EnumerationOptions类的具体用法?C# EnumerationOptions怎么用?C# EnumerationOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EnumerationOptions类属于System.Management命名空间,在下文中一共展示了EnumerationOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var sb = new StringBuilder();
var scope = Wmi.GetScope();
var enumOptions = new EnumerationOptions { EnsureLocatable = true };
var processor = Processor.GetInstances(scope, enumOptions).Cast<Processor>().FirstOrDefault();
if (processor != null)
{
sb.AppendLine(string.Format("{0,-22} {1}", "Name:", processor.Name));
sb.AppendLine(string.Format("{0,-22} {1} ({2}-bit)", "Architecture:",
processor.Architecture.GetDescription(), processor.DataWidth));
sb.AppendLine(string.Format("{0,-22} {1}", "Processor ID:", processor.ProcessorId));
}
sb.AppendLine();
var os = new OperatingSystem0(scope);
{
sb.AppendLine(string.Format("{0,-22} {1} [{2}] ({3})", "Operating System:", os.Caption, os.Version, os.OSArchitecture));
sb.AppendLine(string.Format("{0,-22} {1:yyyy-MM-dd HH:mm:ss} ({2,3:dd} days {2:hh}:{2:mm}:{2:ss})",
"Install Date", os.InstallDate, (DateTime.Now - os.InstallDate)));
sb.AppendLine(string.Format("{0,-22} {1:yyyy-MM-dd HH:mm:ss} ({2,3:dd} days {2:hh}:{2:mm}:{2:ss})",
"Last boot", os.LastBootUpTime, (DateTime.Now - os.LastBootUpTime)));
}
sb.AppendLine();
Console.WriteLine(sb.ToString());
Console.Write("Press any key to continue...");
Console.ReadKey();
}
示例2: TriggerClientAction
public void TriggerClientAction(string scheduleId, ManagementScope remote)
{
ObjectQuery query = new SelectQuery("SELECT * FROM meta_class WHERE __Class = 'SMS_Client'");
var eOption = new EnumerationOptions();
var searcher = new ManagementObjectSearcher(remote, query, eOption);
var queryCollection = searcher.Get();
foreach (ManagementObject ro in queryCollection)
{
// Obtain in-parameters for the method
var inParams = ro.GetMethodParameters("TriggerSchedule");
// Add the input parameters.
inParams["sScheduleID"] = scheduleId;
try
{
var outParams = ro.InvokeMethod("TriggerSchedule", inParams, null);
ResultConsole.Instance.AddConsoleLine($"Returned with value {_wmiServices.GetProcessReturnValueText(Convert.ToInt32(outParams["ReturnValue"]))}");
}
catch (Exception ex)
{
ResultConsole.Instance.AddConsoleLine("Error performing SCCM Client Function due to an error.");
_logger.LogError($"Error performing SCCM Client Function due to the following error: {ex.Message}", ex);
}
}
}
示例3: GetManagementObjects
static IEnumerable<byte[]> GetManagementObjects()
{
var options = new EnumerationOptions {Rewindable = false, ReturnImmediately = true};
var scope = new ManagementScope(ManagementPath.DefaultPath);
var query = new ObjectQuery("SELECT * FROM Win32_NetworkAdapter");
var searcher = new ManagementObjectSearcher(scope, query, options);
ManagementObjectCollection collection = searcher.Get();
foreach (ManagementObject obj in collection)
{
byte[] bytes;
try
{
PropertyData propertyData = obj.Properties["MACAddress"];
string propertyValue = propertyData.Value.ToString();
bytes = propertyValue.Split(':')
.Select(x => byte.Parse(x, NumberStyles.HexNumber))
.ToArray();
}
catch (Exception)
{
continue;
}
if (bytes.Length == 6)
yield return bytes;
}
}
示例4: Should_pull_using_WMI
public void Should_pull_using_WMI()
{
var options = new EnumerationOptions {Rewindable = false, ReturnImmediately = true};
var scope = new ManagementScope(ManagementPath.DefaultPath);
var query = new ObjectQuery("SELECT * FROM Win32_NetworkAdapter");
var searcher = new ManagementObjectSearcher(scope, query, options);
ManagementObjectCollection collection = searcher.Get();
foreach (ManagementObject obj in collection)
{
try
{
PropertyData typeData = obj.Properties["AdapterType"];
string typeValue = typeData.Value.ToString();
PropertyData propertyData = obj.Properties["MACAddress"];
string propertyValue = propertyData.Value.ToString();
Console.WriteLine("Adapter: {0}-{1}", propertyValue, typeValue);
}
catch (Exception ex)
{
}
}
}
示例5: MyGetSearcher
private static ManagementObjectSearcher MyGetSearcher(ManagementScope scope, string myquery)
{
EnumerationOptions options = new EnumerationOptions();
options.Rewindable = false;
options.ReturnImmediately = true;
return new ManagementObjectSearcher(scope, new ObjectQuery(myquery), options);
}
示例6: ExecuteQueryReturnJSON
public string ExecuteQueryReturnJSON(string query)
{
ManagementObjectSearcher searcher;
searcher = new ManagementObjectSearcher(Scope, query);
EnumerationOptions options = new EnumerationOptions();
options.ReturnImmediately = true;
ManagementObjectCollection res = searcher.Get();
return DataConverter.DataTableToJSON(WmiToDataTable(res));
}
示例7: ManagementObjectCollection
//internal IWbemServices GetIWbemServices () {
// return scope.GetIWbemServices ();
//}
//internal ConnectionOptions Connection {
// get { return scope.Connection; }
//}
//Constructor
internal ManagementObjectCollection(
ManagementScope scope,
EnumerationOptions options,
IEnumWbemClassObject enumWbem)
{
if (null != options)
this.options = (EnumerationOptions) options.Clone();
else
this.options = new EnumerationOptions ();
if (null != scope)
this.scope = (ManagementScope)scope.Clone ();
else
this.scope = ManagementScope._Clone(null);
this.enumWbem = enumWbem;
}
示例8: ExecuteTask
protected override void ExecuteTask() {
try {
ObjectQuery query = new ObjectQuery("SELECT * FROM MSBTS_Orchestration"
+ " WHERE Name = " + SqlQuote(OrchestrationName));
EnumerationOptions enumerationOptions = new EnumerationOptions();
enumerationOptions.ReturnImmediately = false;
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query, enumerationOptions)) {
ManagementObjectCollection orchestrations = searcher.Get();
// ensure we found a matching orchestration
if (orchestrations.Count == 0) {
throw new BuildException(string.Format(CultureInfo.InvariantCulture,
"Orchestration \"{0}\" does not exist on \"{0}\".",
OrchestrationName, Server), Location);
}
// perform actions on each matching orchestration
foreach (ManagementObject orchestration in orchestrations) {
try {
// invoke each action in the order in which they
// were added (in the build file)
foreach (IOrchestrationAction action in _actions) {
action.Invoke(orchestration);
}
} catch (Exception ex) {
if (FailOnError) {
throw;
}
// log exception and continue processing the actions
// for the next orchestration
Log(Level.Error, ex.Message);
}
}
}
} catch (BuildException) {
throw;
} catch (Exception ex) {
throw new BuildException("Error looking up orchestration(s).",
Location, ex);
}
}
示例9: WmiInformationGatherer
/// <summary>
/// Targets the specified namespace on a specified computer, and scavenges it for all classes, if the bool is set to true. If false, it is used to setup the ManagementPath which
/// consists of the specified system and specified namespace
/// </summary>
/// <param name="pNamespace"></param>
/// <param name="pHostName"></param>
public WmiInformationGatherer(string pNamespace, string pHostName, bool pScavenge)
{
mRemoteWmiPath = new ManagementPath(@"\\" + pHostName + @"\root\" + pNamespace);
if (pScavenge)
{
try
{
ManagementClass managementClass = new ManagementClass(mRemoteWmiPath);
EnumerationOptions scavengeOptions = new EnumerationOptions();
scavengeOptions.EnumerateDeep = false;
WmiResults = new WmiResult(pHostName);
WmiResults.PopulateClassesList(managementClass.GetSubclasses());
}
catch (Exception e)
{
WmiResults.WmiError = e;
}
}
}
示例10: ManagementObjectSearcher
public ManagementObjectSearcher(ManagementScope scope, ObjectQuery query, EnumerationOptions options)
{
this.scope = ManagementScope._Clone(scope);
if (query != null)
{
this.query = (ObjectQuery) query.Clone();
}
else
{
this.query = new ObjectQuery();
}
if (options != null)
{
this.options = (EnumerationOptions) options.Clone();
}
else
{
this.options = new EnumerationOptions();
}
}
示例11: ManagementObjectCollection
internal ManagementObjectCollection(ManagementScope scope, EnumerationOptions options, IEnumWbemClassObject enumWbem)
{
if (options != null)
{
this.options = (EnumerationOptions) options.Clone();
}
else
{
this.options = new EnumerationOptions();
}
if (scope != null)
{
this.scope = scope.Clone();
}
else
{
this.scope = ManagementScope._Clone(null);
}
this.enumWbem = enumWbem;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:20,代码来源:ManagementObjectCollection.cs
示例12: GetInstances
public static BcdObjectCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions)
{
if ((mgmtScope == null)) {
if ((statMgmtScope == null)) {
mgmtScope = new System.Management.ManagementScope();
mgmtScope.Path.NamespacePath = "root\\WMI";
}
else {
mgmtScope = statMgmtScope;
}
}
System.Management.ManagementPath pathObj = new System.Management.ManagementPath();
pathObj.ClassName = "BcdObject";
pathObj.NamespacePath = "root\\WMI";
System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null);
if ((enumOptions == null)) {
enumOptions = new System.Management.EnumerationOptions();
enumOptions.EnsureLocatable = true;
}
return new BcdObjectCollection(clsObject.GetInstances(enumOptions));
}
示例13: ConnectGetWMI
//.........这里部分代码省略.........
}
connectArray.Add(scope);
currentNamesapceCount++;
}
if ((sinkArray.Count != namespaceArray.Count) || (connectArray.Count != namespaceArray.Count)) // not expected throw exception
{
internalException = new InvalidOperationException();
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
return;
}
currentNamesapceCount = 0;
while (currentNamesapceCount < namespaceArray.Count)
{
string connectNamespace = (string)namespaceArray[currentNamesapceCount];
ManagementObjectSearcher searcher = getObject.GetObjectList((ManagementScope)connectArray[currentNamesapceCount]);
if (searcher == null)
{
currentNamesapceCount++;
continue;
}
if (topNamespace)
{
topNamespace = false;
searcher.Get(_results);
}
else
{
searcher.Get((ManagementOperationObserver)sinkArray[currentNamesapceCount]);
}
currentNamesapceCount++;
}
}
else
{
ManagementScope scope = new ManagementScope(WMIHelper.GetScopeString(_computerName, getObject.Namespace), options);
scope.Connect();
ManagementObjectSearcher searcher = getObject.GetObjectList(scope);
if (searcher == null)
throw new ManagementException();
searcher.Get(_results);
}
}
catch (ManagementException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
catch (System.Runtime.InteropServices.COMException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
catch (System.UnauthorizedAccessException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
return;
}
string queryString = string.IsNullOrEmpty(getObject.Query) ? GetWmiQueryString() : getObject.Query;
ObjectQuery query = new ObjectQuery(queryString.ToString());
try
{
ManagementScope scope = new ManagementScope(WMIHelper.GetScopeString(_computerName, getObject.Namespace), options);
EnumerationOptions enumOptions = new EnumerationOptions();
enumOptions.UseAmendedQualifiers = getObject.Amended;
enumOptions.DirectRead = getObject.DirectRead;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query, enumOptions);
// Execute the WMI command for each count value.
for (int i = 0; i < _cmdCount; ++i)
{
searcher.Get(_results);
}
}
catch (ManagementException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
catch (System.Runtime.InteropServices.COMException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
catch (System.UnauthorizedAccessException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
}
示例14: GetInstances
public static PerfFormattedData_Counters_ProcessorInformationCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions)
{
if ((mgmtScope == null)) {
if ((statMgmtScope == null)) {
mgmtScope = new System.Management.ManagementScope();
mgmtScope.Path.NamespacePath = "root\\CIMV2";
}
else {
mgmtScope = statMgmtScope;
}
}
System.Management.ManagementPath pathObj = new System.Management.ManagementPath();
pathObj.ClassName = "Win32_PerfFormattedData_Counters_ProcessorInformation";
pathObj.NamespacePath = "root\\CIMV2";
System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null);
if ((enumOptions == null)) {
enumOptions = new System.Management.EnumerationOptions();
enumOptions.EnsureLocatable = true;
}
return new PerfFormattedData_Counters_ProcessorInformationCollection(clsObject.GetInstances(enumOptions));
}
开发者ID:OrangeChan,项目名称:cshv3,代码行数:21,代码来源:root.CIMV2.Win32_PerfFormattedData_Counters_ProcessorInformation.cs
示例15: setNewLastPosition
private string setNewLastPosition(ManagementScope scope, EnumerationOptions opt)
{
L.Log(LogType.FILE, LogLevel.INFORM, "setNewLastPosition()| Start: Oldfirst_position:" + first_position);
Int64 lPosition = 0;
SelectQuery query = null;
try
{
string sWhereClause = "";
ValidateMe();
EventLog ev;
if (remote_host == "")
ev = new EventLog(location);
else
ev = new EventLog(location, remote_host);
string sTarih = ManagementDateTimeConverter.ToDmtfDateTime(DateTime.Now.AddHours(-2));
if (EventIDToFilter == "")
{
query = new SelectQuery("select CategoryString,ComputerName, EventIdentifier,Type,Message,RecordNumber,SourceName," +
"TimeGenerated,User from Win32_NtLogEvent where Logfile ='" + location + "' AND TimeGenerated>'" + sTarih + "'");
}
else
{
string[] EventIDArr = EventIDToFilter.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string FilterText = "";
if (EventIDArr.Length < 2)
{
FilterText = "EventIdentifier <> " + EventIDArr[0];
}
else
{
FilterText = "EventIdentifier <> " + EventIDArr[0] + " and ";
for (int f = 0; f < EventIDArr.Length - 2; f++)
{
FilterText += "EventIdentifier <> " + EventIDArr[f] + " and ";
}
FilterText += "EventIdentifier <> " + EventIDArr[EventIDArr.Length - 1];
}
query = new SelectQuery("select CategoryString,ComputerName, EventIdentifier,Type,Message,RecordNumber,SourceName," +
"TimeGenerated,User from Win32_NtLogEvent where " + FilterText + " and Logfile ='" +
location + "' AND TimeGenerated>'" + sTarih + "'");
}
L.Log(LogType.FILE, LogLevel.DEBUG, "setNewLastPosition()| query:" + query.QueryString);
List<ManagementObject> moList = new List<ManagementObject>();
opt.Timeout = System.TimeSpan.MaxValue;
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query, opt))
{
//Int32 count = ev.Entries.Count;
foreach (ManagementObject mObject in searcher.Get())
{
lPosition = Convert.ToInt64(mObject["RecordNumber"]);
L.Log(LogType.FILE, LogLevel.DEBUG, "setNewLastPosition()| :lPosition" + lPosition);
if (fromend == 0)
{
L.Log(LogType.FILE, LogLevel.DEBUG, "setNewLastPosition()| fromend==1:lPosition" + lPosition);
lPosition = lPosition - ev.Entries.Count;
}
break;
}
}
}
catch (Exception exp)
{
L.Log(LogType.FILE, LogLevel.ERROR, "setNewLastPosition()| " + exp.Message);
L.Log(LogType.FILE, LogLevel.ERROR, "setNewLastPosition()| query:" + query.QueryString);
return "0";
}
L.Log(LogType.FILE, LogLevel.DEBUG, "setNewLastPosition()| End :lPosition:" + lPosition.ToString());
return lPosition.ToString();
}