当前位置: 首页>>代码示例>>C#>>正文


C# Management.ManagementScope类代码示例

本文整理汇总了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;
 }
开发者ID:reticon,项目名称:CCMClient,代码行数:31,代码来源:SID.cs

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

示例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());
                 }
             }
         }
     }
 }
开发者ID:JKLFA,项目名称:Craig-s-Utility-Library,代码行数:32,代码来源:OperatingSystem.cs

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

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

示例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;
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:31,代码来源:Disk.cs

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

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

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

示例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();
             }
         }
     }
 }
开发者ID:pengyancai,项目名称:cs-util,代码行数:33,代码来源:BIOS.cs

示例11: WmiWrapper

 public WmiWrapper(ManagementPath path)
 {
     _scope = new ManagementScope(path)
     {
         Options = { Impersonation = ImpersonationLevel.Impersonate }
     };
 }
开发者ID:b1thunt3r,项目名称:WinInfo,代码行数:7,代码来源:WMIWrapper.cs

示例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);
     }
 }
开发者ID:jeffpatton1971,项目名称:mod-hyperv,代码行数:7,代码来源:functions.cs

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

示例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;
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:31,代码来源:Hotfix.cs

示例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);
                    }
                });
        }
开发者ID:GTRsdk,项目名称:HandBrake,代码行数:35,代码来源:DriveDetectService.cs


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