本文整理汇总了C#中System.Management.ManagementScope类的典型用法代码示例。如果您正苦于以下问题:C# ManagementScope类的具体用法?C# ManagementScope怎么用?C# ManagementScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ManagementScope类属于System.Management命名空间,在下文中一共展示了ManagementScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowUserSID
public static string ShowUserSID(string username)
{
// local scope
string[] unames = username.Split("\\".ToCharArray(),2);
string d = "";
string n = "";
d = unames[0];
if (unames.Length < 2)
{
n = unames[0];
d = "US_IBS";
}
else
n = unames[1];
ConnectionOptions co = new ConnectionOptions();
//co.Username = username;
ManagementScope msc = new ManagementScope ("\\root\\cimv2",co);
string queryString = "SELECT * FROM Win32_UserAccount where LocalAccount = false AND SIDType = 1 AND Domain = '" + d+ "' AND Name = '" + n + "'";
//System.Windows.Forms.MessageBox.Show(queryString);
SelectQuery q = new SelectQuery (queryString);
query = new ManagementObjectSearcher(msc, q);
queryCollection = query.Get();
string res=String.Empty;
foreach( ManagementObject mo in queryCollection )
{
// there should be only one here!
res+= mo["SID"].ToString();
//res+= mo["Name"]+"\n";
}
return res;
}
示例2: Run
//private char NULL_VALUE = char(0);
public static ProcessReturnCode Run(string machineName, string commandLine, string args, string currentDirectory)
{
var connOptions = new ConnectionOptions
{
EnablePrivileges = true
};
var scope = new ManagementScope(@"\\{0}\root\cimv2".FormatWith(machineName), connOptions);
scope.Connect();
var managementPath = new ManagementPath(CLASSNAME);
using (var processClass = new ManagementClass(scope, managementPath, new ObjectGetOptions()))
{
var inParams = processClass.GetMethodParameters("Create");
commandLine = System.IO.Path.Combine(currentDirectory, commandLine);
inParams["CommandLine"] = "{0} {1}".FormatWith(commandLine, args);
var outParams = processClass.InvokeMethod("Create", inParams, null);
var rtn = Convert.ToUInt32(outParams["returnValue"]);
var pid = Convert.ToUInt32(outParams["processId"]);
if (pid != 0)
{
WaitForPidToDie(machineName, pid);
}
return (ProcessReturnCode)rtn;
}
}
示例3: GetOperatingSystemInfo
protected virtual void GetOperatingSystemInfo(string Name, string UserName, string Password)
{
if (string.IsNullOrEmpty(Name))
throw new ArgumentNullException("Name");
ManagementScope Scope = null;
if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
{
ConnectionOptions Options = new ConnectionOptions();
Options.Username = UserName;
Options.Password = Password;
Scope = new ManagementScope("\\\\" + Name + "\\root\\cimv2", Options);
}
else
{
Scope = new ManagementScope("\\\\" + Name + "\\root\\cimv2");
}
Scope.Connect();
ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
using (ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query))
{
using (ManagementObjectCollection Collection = Searcher.Get())
{
foreach (ManagementObject TempNetworkAdapter in Collection)
{
if (TempNetworkAdapter.Properties["LastBootUpTime"].Value != null)
{
LastBootUpTime = ManagementDateTimeConverter.ToDateTime(TempNetworkAdapter.Properties["LastBootUpTime"].Value.ToString());
}
}
}
}
}
示例4: checkAntiVirus
public static List<Object[]> checkAntiVirus()
{
List<Object[]> av = new List<Object[]>();
ConnectionOptions _connectionOptions = new ConnectionOptions();
_connectionOptions.EnablePrivileges = true;
_connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope _managementScope = new ManagementScope(string.Format("\\\\{0}\\root\\SecurityCenter2", "localhost"), _connectionOptions);
_managementScope.Connect();
ObjectQuery _objectQuery = new ObjectQuery("SELECT * FROM AntivirusProduct");
ManagementObjectSearcher _managementObjectSearcher = new ManagementObjectSearcher(_managementScope, _objectQuery);
ManagementObjectCollection _managementObjectCollection = _managementObjectSearcher.Get();
if (_managementObjectCollection.Count > 0)
{
Boolean updated = false;
foreach (ManagementObject item in _managementObjectCollection)
{
updated = (item["productState"].ToString() == "266240" || item["productState"].ToString() == "262144");
av.Add(new Object[] { item["displayName"].ToString(), updated });
}
}
return av;
}
示例5: OnCommitted
protected override void OnCommitted(IDictionary savedState)
{
base.OnCommitted (savedState);
// Setting the "Allow Interact with Desktop" option for this service.
ConnectionOptions connOpt = new ConnectionOptions();
connOpt.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope mgmtScope = new ManagementScope(@"root\CIMv2", connOpt);
mgmtScope.Connect();
ManagementObject wmiService = new ManagementObject("Win32_Service.Name='" + ReflectorMgr.ReflectorServiceName + "'");
ManagementBaseObject inParam = wmiService.GetMethodParameters("Change");
inParam["DesktopInteract"] = true;
ManagementBaseObject outParam = wmiService.InvokeMethod("Change", inParam, null);
#region Start the reflector service immediately
try
{
ServiceController sc = new ServiceController("ConferenceXP Reflector Service");
sc.Start();
}
catch (Exception ex)
{
// Don't except - that would cause a rollback. Instead, just tell the user.
RtlAwareMessageBox.Show(null, string.Format(CultureInfo.CurrentCulture, Strings.ServiceStartFailureText,
ex.ToString()), Strings.ServiceStartFailureTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
}
#endregion
}
示例6: ObjectQuery
public static List<EntDisk>GetDiskDetails(ManagementScope scope)
{
_logger.Info("Collecting disk details for machine " + scope.Path.Server);
ObjectQuery query = null;
ManagementObjectSearcher searcher = null;
ManagementObjectCollection objects = null;
List<EntDisk> lstDisk = new List<EntDisk>();
try
{
query = new ObjectQuery("Select * from Win32_DiskDrive");
searcher = new ManagementObjectSearcher(scope, query);
objects = searcher.Get();
lstDisk.Capacity = objects.Count;
foreach (ManagementBaseObject obj in objects)
{
lstDisk.Add(FillDetails(obj));
obj.Dispose();
}
}
catch (Exception e)
{
_logger.Error("Exception is disk collection " + e.Message);
}
finally
{
searcher.Dispose();
}
return lstDisk;
}
示例7: GetScope
public static ManagementScope GetScope(string ns = @"root\cimv2", string server = ".", string username = null, string password = null)
{
var scope = new ManagementScope()
{
Options =
{
Impersonation = ImpersonationLevel.Impersonate,
Authentication = AuthenticationLevel.PacketPrivacy,
EnablePrivileges = true
},
Path = new ManagementPath()
{
NamespacePath = ns,
Server = server
}
};
if (!string.IsNullOrWhiteSpace(username))
scope.Options.Username = username;
if (!string.IsNullOrWhiteSpace(password))
scope.Options.Password = password;
return scope;
}
示例8: GetComPorts
/// <summary>
/// Gets COM port list.
/// </summary>
/// <returns>Enumerable list of COM ports.</returns>
public static IEnumerable<ComPortItem> GetComPorts()
{
var result = new List<ComPortItem>();
ManagementScope connectionScope = new ManagementScope();
SelectQuery serialQuery = new SelectQuery("SELECT * FROM Win32_SerialPort");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(connectionScope, serialQuery);
try
{
foreach (ManagementObject item in searcher.Get())
{
string portName = item["DeviceID"].ToString();
string portDescription = item["DeviceID"].ToString();
// COM port with Arduino is not detected.
// portDescription.Contains("Arduino") is not working.
// I should find out how to get value "Arduino Uno" from "Описание устройства, предоставленное шиной" parameter.
// And where is this parameter?
result.Add(new ComPortItem(portName, portDescription.Contains("Arduino")));
}
}
catch (ManagementException)
{
}
return result;
}
示例9: ConfigureMmioGap
ConfigureMmioGap(
string vmName,
uint gapSize)
{
ManagementScope scope = new ManagementScope(@"root\virtualization\v2");
using (ManagementObject vm = WmiUtilities.GetVirtualMachine(vmName, scope))
using (ManagementObject vssd = WmiUtilities.GetVirtualMachineSettings(vm))
using (ManagementObject vmms = WmiUtilities.GetVirtualMachineManagementService(scope))
using (ManagementBaseObject inParams = vmms.GetMethodParameters("ModifySystemSettings"))
{
Console.WriteLine("Configuring MMIO gap size of Virtual Machine \"{0}\" ({1}) " +
"to {2} MB...", vm["ElementName"], vm["Name"], gapSize);
vssd["LowMmioGapSize"] = gapSize;
inParams["SystemSettings"] = vssd.GetText(TextFormat.CimDtd20);
using (ManagementBaseObject outParams =
vmms.InvokeMethod("ModifySystemSettings", inParams, null))
{
if (WmiUtilities.ValidateOutput(outParams, scope))
{
Console.WriteLine("Configuring MMIO gap size succeeded.\n");
}
}
}
}
示例10: LoadBIOS
/// <summary>
/// Loads the BIOS info
/// </summary>
/// <param name="Name">Computer name</param>
/// <param name="UserName">User name</param>
/// <param name="Password">Password</param>
private void LoadBIOS(string Name, string UserName, string Password)
{
ManagementScope Scope = null;
if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
{
ConnectionOptions Options = new ConnectionOptions();
Options.Username = UserName;
Options.Password = Password;
Scope = new ManagementScope("\\\\" + Name + "\\root\\cimv2", Options);
}
else
{
Scope = new ManagementScope("\\\\" + Name + "\\root\\cimv2");
}
Scope.Connect();
ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_BIOS");
using (ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query))
{
using (ManagementObjectCollection Collection = Searcher.Get())
{
foreach (ManagementObject TempBIOS in Collection)
{
SerialNumber = TempBIOS.Properties["Serialnumber"].Value.ToString();
}
}
}
}
示例11: WmiWrapper
public WmiWrapper(ManagementPath path)
{
_scope = new ManagementScope(path)
{
Options = { Impersonation = ImpersonationLevel.Impersonate }
};
}
示例12: getVhdSettings
public static ManagementObject[] getVhdSettings(ManagementObject virtualMachine, ManagementScope Scope)
{
using (ManagementObject mObject = getSettingData(wmiClass.Msvm_VirtualSystemSettingData.ToString(), wmiClass.Msvm_SettingsDefineState.ToString(), virtualMachine, Scope))
{
return getVHDSettings(mObject);
}
}
示例13: 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;
}
}
示例14: GetHotfixDetails
public static List<EntHotfixes> GetHotfixDetails(ManagementScope scope)
{
_logger.Info("Collecting hotfix for machine " + scope.Path.Server);
ObjectQuery query = null;
ManagementObjectSearcher searcher = null;
ManagementObjectCollection objects = null;
List<EntHotfixes> lstHotfix = new List<EntHotfixes>();
try
{
query = new ObjectQuery("Select * from Win32_QuickFixEngineering");
searcher = new ManagementObjectSearcher(scope, query);
objects = searcher.Get();
lstHotfix.Capacity = objects.Count;
foreach (ManagementBaseObject obj in objects)
{
lstHotfix.Add(FillDetails(obj));
obj.Dispose();
}
}
catch (System.Exception e)
{
_logger.Error("Exception is hotfix collection " + e.Message);
}
finally
{
searcher.Dispose();
}
return lstHotfix;
}
示例15: StartDetection
/// <summary>
/// The start detection.
/// </summary>
/// <param name="action">
/// The detection Action.
/// </param>
public void StartDetection(Action action)
{
ThreadPool.QueueUserWorkItem(
delegate
{
this.detectionAction = action;
var options = new ConnectionOptions { EnablePrivileges = true };
var scope = new ManagementScope(@"root\CIMV2", options);
try
{
var query = new WqlEventQuery
{
EventClassName = "__InstanceModificationEvent",
WithinInterval = TimeSpan.FromSeconds(1),
Condition = @"TargetInstance ISA 'Win32_LogicalDisk' and TargetInstance.DriveType = 5" // DriveType - 5: CDROM
};
this.watcher = new ManagementEventWatcher(scope, query);
this.watcher.EventArrived += this.WatcherEventArrived;
this.watcher.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
});
}