本文整理匯總了C#中System.Management.SelectQuery類的典型用法代碼示例。如果您正苦於以下問題:C# SelectQuery類的具體用法?C# SelectQuery怎麽用?C# SelectQuery使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SelectQuery類屬於System.Management命名空間,在下文中一共展示了SelectQuery類的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: GetBrightnessLevel
/// <summary>
/// Query the brightness setting of the display.
/// </summary>
internal static int GetBrightnessLevel()
{
try
{
var s = new ManagementScope("root\\WMI");
var q = new SelectQuery("WmiMonitorBrightness");
var mos = new ManagementObjectSearcher(s, q);
var moc = mos.Get();
foreach (var managementBaseObject in moc)
{
foreach (var o in managementBaseObject.Properties)
{
if (o.Name == "CurrentBrightness")
return Convert.ToInt32(o.Value);
}
}
moc.Dispose();
mos.Dispose();
}
catch (ManagementException ex)
{
// ignore
// it is possible that laptop lid is closed, and using external monitor
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return 0;
}
示例3: AutodetectCOMPort
/// <summary>
/// Autodetects the COM port.
/// </summary>
/// <param name="description">The description.</param>
/// <returns></returns>
public static string AutodetectCOMPort(string description)
{
var connectionScope = new ManagementScope();
var serialQuery = new SelectQuery("SELECT * FROM Win32_SerialPort");
var searcher = new ManagementObjectSearcher(connectionScope, serialQuery);
try
{
foreach (ManagementObject item in searcher.Get())
{
var desc = item["Description"].ToString();
var deviceId = item["DeviceID"].ToString();
if (desc.Contains(description))
{
return deviceId;
}
}
}
catch (ManagementException)
{
}
return null;
}
示例4: GetProcessUserName
public string GetProcessUserName(int pid)
{
string text1 = null;
SelectQuery query = new SelectQuery("Select * from Win32_Process WHERE processID=" + pid);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
try
{
foreach (ManagementObject disk in searcher.Get())
{
ManagementBaseObject inPar = null;
ManagementBaseObject outPar = null;
inPar = disk.GetMethodParameters("GetOwner");
outPar = disk.InvokeMethod("GetOwner", inPar, null);
text1 = outPar["User"].ToString();
break;
}
}
catch
{
text1 = "SYSTEM";
}
return text1;
}
示例5: AutodetectArduinoPort
// to detect if the correct arduino is connected
private string AutodetectArduinoPort()
{
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())
{
//safe COM port of arduino if arduino with PNPDeviceI: 64935343733351707252 is connected
string desc = item["PNPDeviceID"].ToString();
string deviceId = item["DeviceID"].ToString();
if (desc.Contains("64935343733351707252"))
{
return deviceId;
}
}
}
catch
{
}
return null;
}
示例6: AutodetectArduinoPort
public static List<Microcontroller> AutodetectArduinoPort()
{
ManagementScope connectionScope = new ManagementScope();
SelectQuery serialQuery = new SelectQuery("SELECT * FROM Win32_SerialPort");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(connectionScope, serialQuery);
try
{
List<Microcontroller> mc = null;
foreach (ManagementObject item in searcher.Get())
{
string name = item["Name"].ToString();
string uname = item["UName"].ToString();
string description = item["Description"].ToString();
string deviceId = item["DeviceID"].ToString();
string PNPdeviceId = item["PNPDeviceID"].ToString();
if (description.Contains("Arduino Due") || description.Contains("Arduino Mega 2560") || description.Contains("Arduino One"))
//Temp Check. Needs to compare each return against Text file list when moved to VRAGE.
{
var mcItem = new Microcontroller(name, description, deviceId, PNPdeviceId,11520);
mc.Add(mcItem);
}
}
return mc;
}
catch (ManagementException e)
{
/* Do Nothing */
}
return null;
}
示例7: GetOSAddressWidth
/// <summary>
/// Added by Donnie on 2012/09/19
/// Gets OS address width.
/// </summary>
/// <returns>32 indicates 32-bit OS, and 64 indicates 64-bit OS.</returns>
private UInt16 GetOSAddressWidth()
{
try
{
SelectQuery query = new SelectQuery("select AddressWidth from Win32_Processor");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection moCollection = searcher.Get();
foreach (ManagementObject mo in moCollection)
{
foreach (PropertyData property in mo.Properties)
{
if (property.Name.Equals("AddressWidth"))
{
return Convert.ToUInt16(property.Value);
}
}
}
throw new Exception("Didn't get expected query result from WMI.");
}
catch (Exception ex)
{
throw new Exception("Error occurs in WMI query.", ex.InnerException);
}
}
示例8: GetPropertyValues
//public static IList<string> GetPropertyValues(Connection WMIConnection,
// string SelectQuery,
// string className)
public static IList<Dictionary<string, string>> GetPropertyValues(Connection WMIConnection,
string SelectQuery,
string className)
{
ManagementScope connectionScope = WMIConnection.GetConnectionScope;
//List<string> alProperties = new List<string>();
SelectQuery msQuery = new SelectQuery(SelectQuery);
ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(connectionScope, msQuery);
//Dictionary<string, string> paM = new Dictionary<string, string>();
List<Dictionary<string, string>> allContent = new List<Dictionary<string, string>>();
try
{
foreach (ManagementObject item in searchProcedure.Get())
{
Dictionary<string, string> paM = new Dictionary<string, string>();
foreach (string property in XMLConfig.GetSettings(className))
{
try
{
paM.Add(property, item[property].ToString());
//alProperties.Add(property + ": " + item[property].ToString());
}
catch (SystemException) { /* ignore error */ }
}
allContent.Add(paM);
}
}
catch (ManagementException e)
{
/* Do Nothing */
}
//return alProperties;
return allContent;
}
示例9: GetMetricDefinition
GetMetricDefinition(
string name,
ManagementScope scope)
{
string metricDefQueryWql = string.Format(CultureInfo.InvariantCulture,
"SELECT * FROM CIM_BaseMetricDefinition WHERE ElementName=\"{0}\"", name);
SelectQuery metricDefQuery = new SelectQuery(metricDefQueryWql);
using (ManagementObjectSearcher metricDefSearcher = new ManagementObjectSearcher(
scope, metricDefQuery))
using (ManagementObjectCollection metricDefCollection = metricDefSearcher.Get())
{
//
// There will always only be one metric definition for a given name.
//
if (metricDefCollection.Count != 1)
{
throw new ManagementException(string.Format(CultureInfo.CurrentCulture,
"A single CIM_BaseMetricDefinition derived instance could not be found " +
"for name \"{0}\"", name));
}
ManagementObject metricDef =
WmiUtilities.GetFirstObjectFromCollection(metricDefCollection);
return metricDef;
}
}
示例10: 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);
}
}
}
示例11: GetDiskShareMountInfo
public List<DiskShareMountDTOResponse> GetDiskShareMountInfo()
{
List<DiskShareMountDTOResponse> mounts = new List<DiskShareMountDTOResponse>();
try
{
SelectQuery query = new SelectQuery(
@"select Model, SerialNumber
from Win32_DiskDrive
where Model like '3PARdata%'"
);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject obj in searcher.Get())
{
DiskShareMountDTOResponse share = new DiskShareMountDTOResponse();
share.Volume = GetValueAsString(obj, "Model");
share.Sn = GetValueAsString(obj, "SerialNumber");
mounts.Add(share);
}
}
catch (ManagementException e)
{
Logger.Instance.LogError(e.ToString());
}
return mounts;
}
示例12: autodetectArduinoPort
// Detect arduino com port
private string autodetectArduinoPort()
{
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 desc = item["Description"].ToString();
string deviceId = item["DeviceID"].ToString();
if (desc.Contains("Arduino"))
{
return deviceId;
}
}
}
catch (ManagementException e)
{
/* Do Nothing */
}
return null;
}
示例13: CPU_info
public List<PCU> CPU_info()
{
List<PCU> CPUInfo = new List<PCU>();
System.Management.SelectQuery query = new System.Management.SelectQuery(@"Select Name,NumberOfCores,NumberOfLogicalProcessors,MaxClockSpeed from Win32_Processor");
//initialize the searcher with the query it is supposed to execute
using (System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query))
{
try
{
//execute the query
foreach (System.Management.ManagementObject process in searcher.Get())
{
PCU cpu = new PCU(process["Name"].ToString(), process["NumberOfCores"].ToString(), process["NumberOfLogicalProcessors"].ToString(), process["MaxClockSpeed"].ToString());
CPUInfo.Add(cpu);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
return CPUInfo;
}
示例14: checkForMissingDrivers
public static void checkForMissingDrivers()
{
bool vJoy = false;
bool libUsb = false;
try
{
SelectQuery query = new SelectQuery("Win32_SystemDriver");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
var drivers = searcher.Get();
foreach (var d in drivers)
{
if (d["Name"].ToString() == "vjoy") vJoy = true;
if (d["Name"].ToString().Contains("libusb")) libUsb = true;
if (vJoy && libUsb) break;
}
if (!vJoy)
{
Log(null, new Logging.LogEventArgs("vJoy was not detected, please rerun the installer."));
}
}
catch
{
Log(null, new Logging.LogEventArgs("Driver check failed, (Are you running as Administrator?)"));
}
}
示例15: GetServicesForComputer
private void GetServicesForComputer(string computerName)
{
ManagementScope scope = CreateNewManagementScope(computerName);
SelectQuery query = new SelectQuery("select * from Win32_Service");
try
{
using (var searcher = new ManagementObjectSearcher(scope, query))
{
ManagementObjectCollection services = searcher.Get();
List<string> serviceNames =
(from ManagementObject service in services select service["Caption"].ToString()).ToList();
lstServices.DataSource = serviceNames;
}
}
catch (Exception exception)
{
lstServices.DataSource = null;
lstServices.Items.Clear();
lblErrors.Text = exception.Message;
Console.WriteLine(Resources.MainForm_GetServicesForServer_Error__ + exception.Message);
}
}