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

C# Management.ManagementClass类代码示例

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

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



ManagementClass类属于System.Management命名空间,在下文中一共展示了ManagementClass类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: 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


示例2: ViewModel

        public ViewModel()
        {
            mgt = new ManagementClass("Win32_Processor");
            procs = mgt.GetInstances();

            CPU = new ObservableCollection<Model>();
            timer = new DispatcherTimer();
            random = new Random();
            time = DateTime.Now;
            cpuCounter = new PerformanceCounter();
            cpuCounter.CategoryName = "Processor";
            cpuCounter.CounterName = "% Processor Time";
            cpuCounter.InstanceName = "_Total";
            ramCounter = new PerformanceCounter("Memory", "Available MBytes");
            ProcessorID = GetProcessorID();
            processes = Process.GetProcesses();
            Processes = processes.Length;
            MaximumSpeed = GetMaxClockSpeed();
            LogicalProcessors = GetNumberOfLogicalProcessors();
            Cores = GetNumberOfCores();
            L2Cache = GetL2CacheSize();
            L3Cache = GetL3CacheSize();
            foreach (ManagementObject item in procs)
                L1Cache = ((UInt32)item.Properties["L2CacheSize"].Value / 2).ToString() + " KB";

            timer.Interval = TimeSpan.FromMilliseconds(1000);
            timer.Tick += timer_Tick;
            timer.Start();
            for (int i = 0; i < 60; i++)
            {
                CPU.Add(new Model(time, 0,0));
                time = time.AddSeconds(1);
            }
        }
开发者ID:jcw-,项目名称:sparrowtoolkit,代码行数:34,代码来源:ViewModel.cs


示例3: Shutdown

        public static void Shutdown(string mode)
        {
            if (mode == "WMI")
            {
                ManagementBaseObject mboShutdown = null;
                ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
                mcWin32.Get();

                // Get Security Privilages
                mcWin32.Scope.Options.EnablePrivileges = true;
                ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");

                //Option Flags
                mboShutdownParams["Flags"] = "1";
                mboShutdownParams["Reserved"] = "0";
                foreach (ManagementObject manObj in mcWin32.GetInstances())
                {
                    mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null);
                }
            }
            else if (mode == "Core")
            {
                Process.Start("shutdown", "/s /t 0");
            }
        }
开发者ID:Porterbg,项目名称:Freeflex,代码行数:25,代码来源:Core.cs


示例4: CreateShare

        /// <summary>
        /// Create a share for a given local path, and sets read/write access rights to everybody
        /// </summary>
        /// <param name="sharePath">local path of directory to be shared</param>
        /// <param name="shareName">Share Name</param>
        public static bool CreateShare(string sharePath, string shareName)
        {
            ManagementObject trustee = new ManagementClass("Win32_Trustee").CreateInstance();
            trustee["Domain"] = null;
            trustee["Name"] = "Everyone";
            trustee["SID"] = new Object[] { 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; // everybody

            ManagementObject ace = new ManagementClass("Win32_Ace").CreateInstance();
            ace["AccessMask"] = 2032127; // full access
            ace["AceFlags"] = 0x1 | 0x2; //OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE
            ace["AceType"] = 0; //Access Allowed
            ace["Trustee"] = trustee;

            ManagementObject dacl = new ManagementClass("Win32_SecurityDescriptor").CreateInstance();
            dacl["DACL"] = new Object[] { ace };

            ManagementClass share = new ManagementClass("Win32_Share");
            ManagementBaseObject inParams = share.GetMethodParameters("Create");
            ManagementBaseObject outParams;
            inParams["Description"] = "Create Share Folder";
            inParams["Name"] = shareName;
            inParams["Path"] = sharePath;
            inParams["Type"] = 0x0; // Disk Drive
            inParams["Access"] = dacl;
            outParams = share.InvokeMethod("Create", inParams, null);

            // Check to see if the method invocation was successful
            if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
            {
                //throw new Exception("Unable to share directory.");
                return false;
            }
            return true;
        }
开发者ID:Jeremiahf,项目名称:wix3,代码行数:39,代码来源:FileUtilities.cs


示例5: GetIdentifier

        public static string GetIdentifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
        {
            if (_log.IsTraceEnabled)
            {
                _log.Trace(m => m(string.Format("wmiClass:{0}, wmiProperty:{1}, wmiMustBeTrue:{2}", wmiClass, wmiProperty, wmiMustBeTrue)));
            }

            string result = "";
            var managementClass = new ManagementClass(wmiClass);
            var moc = managementClass.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if (mo[wmiMustBeTrue].ToString() == "True")
                {
                    //Only get the first one
                    if (result == "")
                    {
                        try
                        {
                            result = mo[wmiProperty].ToString();
                            break;
                        }
                        catch(Exception ex)
                        {
                            _log.Warn(ex);
                        }
                    }
                }
            }
            return result;
        }
开发者ID:fr4gles,项目名称:Building-Blocks,代码行数:31,代码来源:HardwareIdentifiers.cs


示例6: Create

        /// <summary>
        /// Create a Send Handler.
        /// </summary>
        /// <param name="adapterName">The Adapter name.</param>
        /// <param name="hostName">The Host name.</param>
        /// <param name="isDefault">Indicating if the Handler is the default.</param>
        public static void Create(string adapterName, string hostName, bool isDefault)
        {
            PutOptions options = new PutOptions();
            options.Type = PutType.CreateOnly;
            using (ManagementClass handlerManagementClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_SendHandler2", null))
            {
                foreach (ManagementObject handler in handlerManagementClass.GetInstances())
                {
                    if ((string)handler["AdapterName"] == adapterName && (string)handler["HostName"] == hostName)
                    {
                        handler.Delete();
                    }
                }

                ManagementObject handlerInstance = handlerManagementClass.CreateInstance();
                if (handlerInstance == null)
                {
                    throw new CoreException("Could not create Management Object.");
                }

                handlerInstance["AdapterName"] = adapterName;
                handlerInstance["HostName"] = hostName;
                handlerInstance["IsDefault"] = isDefault;
                handlerInstance.Put(options);
            }
        }
开发者ID:StealFocus,项目名称:Core,代码行数:32,代码来源:SendHandler.cs


示例7: LoadDeviceList

        private void LoadDeviceList()
        {
            devices.Clear();
            devices.Add(new SoundDevice("Default", "0000", "0000"));

            ManagementPath path = new ManagementPath();
            ManagementClass devs = null;
            path.Server = ".";
            path.NamespacePath = @"root\CIMV2";
            path.RelativePath = @"Win32_SoundDevice";
            using (devs = new ManagementClass(new ManagementScope(path), path, new ObjectGetOptions(null, new TimeSpan(0, 0, 0, 2), true)))
            {
                ManagementObjectCollection moc = devs.GetInstances();

                foreach (ManagementObject mo in moc)
                {
                    PropertyDataCollection devsProperties = mo.Properties;
                    string devid = devsProperties["DeviceID"].Value.ToString();
                    if (devid.Contains("PID_"))
                    {
                        string vid = devid.Substring(devid.IndexOf("VID_") + 4, 4);
                        string pid = devid.Substring(devid.IndexOf("PID_") + 4, 4);

                        devices.Add(new SoundDevice(devsProperties["Caption"].Value.ToString(), vid, pid));

                    }
                }
            }
        }
开发者ID:suleymansahin07,项目名称:NoCableLauncher,代码行数:29,代码来源:Settings.cs


示例8: GetDiskVolumeSerialNumber

 //获取硬盘卷标号
 public static string GetDiskVolumeSerialNumber()
 {
     ManagementClass mc = new ManagementClass("win32_NetworkAdapterConfiguration");
     ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
     disk.Get();
     return disk.GetPropertyValue("VolumeSerialNumber").ToString();
 }
开发者ID:huaminglee,项目名称:yousoftbath,代码行数:8,代码来源:RegisterForm.cs


示例9: getComPorts

        public static string[] getComPorts()
        {
            var list = new ArrayList();

            ManagementClass win32_pnpentity = new ManagementClass("Win32_PnPEntity");
            ManagementObjectCollection col = win32_pnpentity.GetInstances();

            Regex reg = new Regex(".+\\((?<port>COM\\d+)\\)");

            foreach (ManagementObject obj in col)
            {
                // name : "USB Serial Port(COM??)"
                string name = (string)obj.GetPropertyValue("name");
                if (name != null && name.Contains("(COM"))
                {
                    // "USB Serial Port(COM??)" -> COM??
                    Match m = reg.Match(name);
                    string port = m.Groups["port"].Value;

                    // description : "USB Serial Port"
                    string desc = (string)obj.GetPropertyValue("Description");

                    // result string : "COM?? (USB Serial Port)"
                    list.Add(port + " (" + desc + ")");
                }
            }

            ComPortComparer comp = new ComPortComparer();
            list.Sort(comp);

            return (string[])list.ToArray(typeof(string));
        }
开发者ID:yoggy,项目名称:enumcomport,代码行数:32,代码来源:EnumComPort.cs


示例10: getNetworkAdapters

 /// <summary>
 /// Retorna una lista de adaptadores de red disponibles en la máquina
 /// Si ocurre un error se arroja una Excepción
 /// </summary>
 /// <returns></returns>
 public static List<NetworkAdapter> getNetworkAdapters()
 {
     try
     {
         List<NetworkAdapter> adapters = new List<NetworkAdapter>();
         ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
         ManagementObjectCollection objMOC = objMC.GetInstances();
         foreach (ManagementObject objMO in objMOC)
         {
             if(true)
             {
                 NetworkAdapter adapter = new NetworkAdapter();
                 adapter.Id = (String)objMO["SettingID"];
                 adapter.Description = (String)objMO["Description"];
                 adapter.Index = (UInt32)objMO["Index"];
                 adapters.Add(adapter);
             }
         }
         return adapters;
     }
     catch (ThreadAbortException e)
     {
         throw e;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
开发者ID:uriel291029,项目名称:High-Level-MANET-Protocol,代码行数:34,代码来源:SystemHandler.cs


示例11: DeviceInformation

 public string DeviceInformation(string stringIn)
 {
     StringBuilder StringBuilder1 = new StringBuilder(string.Empty);
     ManagementClass ManagementClass1 = new ManagementClass(stringIn);
     //Create a ManagementObjectCollection to loop through
     ManagementObjectCollection ManagemenobjCol = ManagementClass1.GetInstances();
     //Get the properties in the class
     PropertyDataCollection properties = ManagementClass1.Properties;
     foreach (ManagementObject obj in ManagemenobjCol)
     {
         foreach (PropertyData property in properties)
         {
             try
             {
                 // resit pres pole kde budou nazvy parametru co me zajimaji
                 if(property.Name.Equals("Name"))
                 StringBuilder1.AppendLine(property.Name + ":  " +
                   obj.Properties[property.Name].Value.ToString());
             }
             catch
             {
                 //Add codes to manage more informations
             }
         }
         StringBuilder1.AppendLine();
     }
     return StringBuilder1.ToString();
 }
开发者ID:VojtechSindler,项目名称:HoperInfo,代码行数:28,代码来源:Device_information.cs


示例12: GetComputerId

 /// <summary>
 /// 获取机器码(根据XCore定制的规则)
 /// </summary>
 /// <returns>当前主机的机器码</returns>
 public static String GetComputerId()
 {
     String DiskDriveid = String.Empty;
     String CPUid = String.Empty;
     ManagementClass mcdisk = new ManagementClass(strUtil.GetStringByUnicode(@"\u0057\u0069\u006e\u0033\u0032\u005f\u0044\u0069\u0073\u006b\u0044\u0072\u0069\u0076\u0065"));
     foreach (ManagementObject mo in mcdisk.GetInstances())
     {
         DiskDriveid = (string)mo.Properties["Model"].Value;
         break;
     }
     ManagementClass mccpu = new ManagementClass(strUtil.GetStringByUnicode(@"\u0057\u0069\u006e\u0033\u0032\u005f\u0050\u0072\u006f\u0063\u0065\u0073\u0073\u006f\u0072"));
     foreach (ManagementObject mo in mccpu.GetInstances())
     {
         CPUid = (string)mo.Properties["ProcessorId"].Value;
         break;
     }
     Int64 diskid = DiskDriveid.GetHashCode();
     Int64 cpuid = CPUid.GetHashCode();
     Int64 computerid = ((diskid > 0 ? diskid : -diskid) % 10000000) * ((cpuid > 0 ? cpuid : -cpuid) % 10000000);
     if (computerid > 100000000000)
         computerid = computerid % 1000000000000;
     else if (computerid < 100000000000)
         computerid += 100000000000;
     return computerid.ToString();
 }
开发者ID:mfz888,项目名称:xcore,代码行数:29,代码来源:Util.cs


示例13: FindMACAddress

 public string FindMACAddress()
 {
     //create out management class object using the
     //Win32_NetworkAdapterConfiguration class to get the attributes
     //of the network adapter
     ManagementClass mgmt = new ManagementClass("Win32_NetworkAdapterConfiguration");
     //create our ManagementObjectCollection to get the attributes with
     ManagementObjectCollection objCol = mgmt.GetInstances();
     string address = String.Empty;
     //loop through all the objects we find
     foreach (ManagementObject obj in objCol)
     {
         if (address == String.Empty)  // only return MAC Address from first card
         {
             //grab the value from the first network adapter we find
             //you can change the string to an array and get all
             //network adapters found as well
             //check to see if the adapter's IPEnabled
             //equals true
             if ((bool)obj["IPEnabled"] == true)
             {
                 address = obj["MacAddress"].ToString();
             }
         }
         //dispose of our object
         obj.Dispose();
     }
     //replace the ":" with an empty space, this could also
     //be removed if you wish
     address = address.Replace(":", "");
     //return the mac address
     return address;
 }
开发者ID:BjkGkh,项目名称:Custom-R2,代码行数:33,代码来源:LicenceProvider.cs


示例14: CheckDeviceMacadress

        public bool CheckDeviceMacadress(string strMacadress)
        {
           
            MacAdress = strMacadress;
           
            ManagementPath cmPath = new ManagementPath("root\\sms\\site_PS1:SMS_R_SYSTEM"); 
            ManagementClass cmClass = new ManagementClass(cmPath);
            ManagementObjectCollection cmCollection = cmClass.GetInstances();

            DeviceFound = false;

            foreach (ManagementObject deviceInfo in cmCollection)
            {
                string[] listCmDeviceMacAdresses = (string[])deviceInfo["MACAddresses"];
                foreach (string MacAdressExist in listCmDeviceMacAdresses)
                {
                    if (MacAdressExist == MacAdress)
                    {
                        DeviceFound = true;
                    }
                    
                }
         
            }

            return DeviceFound;
        }
开发者ID:aramiz84,项目名称:sllCreateComputer,代码行数:27,代码来源:CheckMacAdress.cs


示例15: GetCPUProperties

        /// <summary>
        /// 获取 CPU 属性参数
        /// </summary>
        /// <returns>返回 CPU 属性参数</returns>
        public static string GetCPUProperties()
        {
            // Get the WMI class
            ManagementClass c = new ManagementClass(new ManagementPath("Win32_Processor"));
            // Get the properties in the class
            ManagementObjectCollection moc = c.GetInstances();

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            // display the properties
            sb.AppendLine("Property Names: ");
            sb.AppendLine("=================");
            foreach (ManagementObject mo in moc)
            {
                PropertyDataCollection properties = mo.Properties;
                //获取内核数代码
                sb.AppendLine("物理内核数:" + properties["NumberOfCores"].Value);
                sb.AppendLine("逻辑内核数:" + properties["NumberOfLogicalProcessors"].Value);
                //其他属性获取代码
                foreach (PropertyData property in properties)
                {
                    sb.AppendLine(property.Name + ":" + property.Value);
                }
            }
            string s = sb.ToString();
            return s;
        }
开发者ID:cheehwasun,项目名称:BaiduPCS_NET,代码行数:30,代码来源:Utils.cs


示例16: identifier

 //Return a hardware identifier
 private static string identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
 {
     string result = "";
     System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
     System.Management.ManagementObjectCollection moc = mc.GetInstances();
     foreach (System.Management.ManagementObject mo in moc)
     {
         if (mo[wmiMustBeTrue].ToString() == "True")
         {
             //Only get the first one
             if (result == "")
             {
                 try
                 {
                     result = mo[wmiProperty].ToString();
                     break;
                 }
                 catch
                 {
                 }
             }
         }
     }
     return result;
 }
开发者ID:RFranta,项目名称:UVDLPSlicerController,代码行数:26,代码来源:FingerPrint.cs


示例17: Create

        /// <summary>
        /// Create a Receive Handler.
        /// </summary>
        /// <param name="adapterName">The Adapter name.</param>
        /// <param name="hostName">The Host name.</param>
        public static void Create(string adapterName, string hostName)
        {
            PutOptions options = new PutOptions();
            options.Type = PutType.CreateOnly;
            using (ManagementClass handlerManagementClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_ReceiveHandler", null))
            {
                foreach (ManagementObject handler in handlerManagementClass.GetInstances())
                {
                    if ((string)handler["AdapterName"] == adapterName && (string)handler["HostName"] == hostName)
                    {
                        handler.Delete();
                    }
                }

                ManagementObject recieveHandlerManager = handlerManagementClass.CreateInstance();
                if (recieveHandlerManager == null)
                {
                    throw new BizTalkExtensionsException("Could not create Management Object.");
                }

                recieveHandlerManager["AdapterName"] = adapterName;
                recieveHandlerManager["HostName"] = hostName;
                recieveHandlerManager.Put(options);
            }
        }
开发者ID:StealFocus,项目名称:BizTalkExtensions,代码行数:30,代码来源:ReceiveHandler.cs


示例18: GetMacAddress

 public List<String> GetMacAddress()
 {
     List<String> macs = new List<string>();
     try
     {
         string mac = "";
         ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
         ManagementObjectCollection moc = mc.GetInstances();
         foreach (ManagementObject mo in moc)
         {
             if ((bool)mo["IPEnabled"])
             {
                 mac = mo["MacAddress"].ToString();
                 macs.Add(mac);
             }
         }
         moc = null;
         mc = null;
     }
     catch(Exception ex)
     {
         //_log.Error("MacAddress get error",ex);
     }
     return macs;
 }
开发者ID:raindyi,项目名称:BusinessReport,代码行数:25,代码来源:InforHelper.cs


示例19: GetDeviceInfo

        public DeviceDTOResponse GetDeviceInfo()
        {
            DeviceDTOResponse device = new DeviceDTOResponse();

            try
            {
                ManagementClass mc = new ManagementClass("Win32_ComputerSystemProduct");

                foreach (ManagementObject obj in mc.GetInstances())
                {
                    device.Label = GetValueAsString(obj, "Name");
                    device.Sn = GetValueAsString(obj, "IdentifyingNumber");
                    device.Caption = GetValueAsString(obj, "Caption");
                    device.Vendor = GetValueAsString(obj, "Vendor");
                    device.Version = GetValueAsString(obj, "Version");

                    break;
                }
            }
            catch (ManagementException e)
            {
                Logger.Instance.LogError(e.ToString());
            }

            return device;
        }
开发者ID:Makdaam,项目名称:ralph,代码行数:26,代码来源:WMIDetectorSource.cs


示例20: SendInstallData

        private static void SendInstallData(string error)
        {
            try
            {
                using (var client = new WebClient())
                {
                    var data = new NameValueCollection();
                    data.Add("error", error);
                    data.Add("computername", SystemInformation.ComputerName);

                    using (var mgmt = new ManagementClass("Win32_OperatingSystem"))
                    {
                        try
                        {
                            foreach (ManagementObject mgmtObj in mgmt.GetInstances())
                            {
                                // Just get first value.
                                data.Add("os", mgmtObj["Caption"].ToString().Trim());
                                break;
                            }
                        }
                        catch { }
                        var result = System.Text.Encoding.Default.GetString(client.UploadValues("http://www.filmkhoj.com/api/install", data));
                    }
                }
            }
            catch { }
        }
开发者ID:huoxudong125,项目名称:VideoSearch,代码行数:28,代码来源:EthicalRestartForm.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Management.ManagementEventWatcher类代码示例发布时间:2022-05-26
下一篇:
C# Management.ManagementBaseObject类代码示例发布时间: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