• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Management.SelectQuery类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Management.SelectQuery的典型用法代码示例。如果您正苦于以下问题:C# SelectQuery类的具体用法?C# SelectQuery怎么用?C# SelectQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SelectQuery类属于System.Management命名空间,在下文中一共展示了SelectQuery类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
 }
开发者ID:reticon,项目名称:CCMClient,代码行数:31,代码来源:SID.cs


示例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;
        }
开发者ID:navhaxs,项目名称:BrightnessTray,代码行数:36,代码来源:WmiFunctions.cs


示例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;
        }
开发者ID:andreigec,项目名称:ANDREICSLIB,代码行数:30,代码来源:DeviceUpdates.cs


示例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;
        }
开发者ID:penguin016,项目名称:Rewrite4,代码行数:25,代码来源:readproc.cs


示例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;
        }
开发者ID:jorisadri,项目名称:OAMK-RunningMat,代码行数:26,代码来源:Speed.cs


示例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;
        }
开发者ID:Geneticus,项目名称:SE-ArduinoTest-App,代码行数:35,代码来源:ArdunioController.cs


示例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);
            }
        }
开发者ID:Donnie888,项目名称:LxServer,代码行数:30,代码来源:SQLHelper.cs


示例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;
        }
开发者ID:Erkan-Yilmaz,项目名称:AutomationTestFramework,代码行数:38,代码来源:WMIReader.cs


示例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;
            }
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:29,代码来源:MetricUtilities.cs


示例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);
                }
            }
        }
开发者ID:ZXeno,项目名称:Andromeda,代码行数:28,代码来源:SccmClientServices.cs


示例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;
        }
开发者ID:Makdaam,项目名称:ralph,代码行数:29,代码来源:WMIDetectorSource.cs


示例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;
        }
开发者ID:kadmelia,项目名称:VSLiquidDuino,代码行数:27,代码来源:Screen.cs


示例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;
        }
开发者ID:VojtechSindler,项目名称:HoperInfo,代码行数:25,代码来源:System_information.cs


示例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?)"));
     }
 }
开发者ID:nawns,项目名称:lundgren,代码行数:25,代码来源:SystemHelper.cs


示例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);
            }
        }
开发者ID:oblivious,项目名称:Oblivious,代码行数:26,代码来源:MainForm.cs


示例16: 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;
        }
开发者ID:AlloBardo,项目名称:robot-mitya,代码行数:32,代码来源:ConsoleSettingsHelper.cs


示例17: Button_Click_1

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
            ManagementObjectSearcher search = new ManagementObjectSearcher(query);

            for (int i = 1; i <= 12; i++)
            {
                query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus="+i.ToString());
                search = new ManagementObjectSearcher(query);
                foreach (ManagementObject result in search.Get())
                {
                    NetworkAdapter adapter = new NetworkAdapter(result);

                    // Identify the adapter you wish to disable here.
                    // In particular, check the AdapterType and
                    // Description properties.

                    // Here, we're selecting the LAN adapters.
                    //if (adapter.AdapterType.Equals("Ethernet 802.3"))
                    //{
                    //    adapter.Enable();
                    //}
                    if (adapter.AdapterType.Equals("Wireless"))
                    {
                        adapter.Enable();
                    }
                }
            }
        }
开发者ID:Pawel-Marcin-Chojnacki,项目名称:ResetConnection,代码行数:29,代码来源:MainWindow.xaml.cs


示例18: GetUserSid

		/// <summary>
		/// Return the SID associated to a username
		/// </summary>
		/// <param name="userName">SID of username to get.</param>
		/// <returns>Return a string like S-1-5-21-1844237615-73586283-725345543-1003</returns>
		public static string GetUserSid (string userName) 
		{ 
			ManagementObjectSearcher	query; 
			ManagementObjectCollection	queryCollection; 

			// local scope 
			ConnectionOptions co	= new ConnectionOptions(); 
			co.Username				= userName; 
			ManagementScope msc		= new ManagementScope ("\\root\\cimv2",co); 
			string queryString		= "SELECT * FROM Win32_UserAccount where name='" +co.Username  +"'"; 
			SelectQuery q			= new SelectQuery (queryString); 
			query					= new ManagementObjectSearcher(msc, q); 
			queryCollection			= query.Get(); 
			
			/*
			string res				= StringUtility.CreateEmptyString (); 
			foreach(ManagementObject mo in queryCollection)
			{ 
				// there should be only one here! 
				res+= mo["SID"].ToString(); 
			} 
			*/
			StringBuilder LocalStringBuilder = new StringBuilder();
			foreach(ManagementObject mo in queryCollection)
			{
				LocalStringBuilder.Append (mo["SID"].ToString ());
			}
			
			return LocalStringBuilder.ToString ();
		} 
开发者ID:tdhieu,项目名称:openvss,代码行数:35,代码来源:SystemUtility.cs


示例19: GetAllProcesses

        public IEnumerable<Database.Models.Process> GetAllProcesses()
        {
            string[] propertiesToSelect = new[] { "Handle", "ProcessId", "Name" };
            SelectQuery processQuery = new SelectQuery("Win32_Process", null, propertiesToSelect);

            List<Database.Models.Process> proceses = new List<Database.Models.Process>();

            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(processQuery))
            {
                using (ManagementObjectCollection processes = searcher.Get())
                {
                    foreach (ManagementObject process in processes)
                    {
                        object[] outParameters = new object[3];
                        uint result = (uint) process.InvokeMethod("GetOwner", outParameters);

                        if (result == 0)
                        {
            #if (DEBUG)
                            Console.WriteLine("{0}\\{1} - {2}", outParameters[Domain], outParameters[Username],
                                              process["Name"]);
            #endif
                            //TODO Search for Account by name adding ID
                            proceses.Add(new Database.Models.Process
                                {
                                    Name = (string) process["Name"],
                                    CreatedAt = DateTime.Now,
                                    UpdatedAt = DateTime.Now
                                });
                        }
                    }
                }
            }
            return proceses;
        }
开发者ID:rizowski,项目名称:CompuLock,代码行数:35,代码来源:ProcessManager.cs


示例20: tsbRun_Click

        private void tsbRun_Click(object sender, EventArgs e)
        {
            SelectQuery query = new SelectQuery("SELECT * FROM Win32_UserAccount");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
            foreach (ManagementObject os in searcher.Get())
            {
                this.txtResult.AppendText(os["Name"] + ";");
            }
            this.txtResult.AppendText("\r\n");

            //连接远程计算机
            ConnectionOptions co = new ConnectionOptions();
            co.Username = "administrator";
            co.Password = "123qwe!";
            System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\192.168.100.51\\root\\cimv2", co);
            //查询远程计算机
            System.Management.ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem");

            ManagementObjectSearcher query1 = new ManagementObjectSearcher(ms, oq);
            ManagementObjectCollection queryCollection1 = query1.Get();
            foreach (ManagementObject mo in queryCollection1)
            {
                string[] ss = { "" };
                mo.InvokeMethod("Reboot", ss);
                this.txtResult.AppendText(mo.ToString());
            }
        }
开发者ID:fanjun365,项目名称:TheDbgTool,代码行数:27,代码来源:WMIForm.cs



注:本文中的System.Management.SelectQuery类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Automation.CmdletProviderContext类代码示例发布时间:2022-05-26
下一篇:
C# Management.RelatedObjectQuery类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap