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


C# Management.ManagementObject类代码示例

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


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

示例1: IisAppPool

 public IisAppPool(ManagementScope scope, string name)
 {
     string path = String.Format("IIsApplicationPool='W3SVC/AppPools/{0}'", name);
     this.scope = scope;
     appPool = new ManagementObject(scope, new ManagementPath(path), null);
     Name = name;
 }
开发者ID:jimbutler,项目名称:bounce,代码行数:7,代码来源:IisAppPool.cs

示例2: HotFixes

 public HotFixes(ManagementObject instance)
 {
     hotFixID = (instance.Properties["HotFixID"].Value != null && instance.Properties["HotFixID"].Value != null)
                    ? instance.Properties["HotFixID"].Value.ToString().Trim()
                    : string.Empty;
     description = (instance.Properties["Description"].Value != null && instance.Properties["Description"].Value != null)
                       ? instance.Properties["Description"].Value.ToString().Trim()
                       : string.Empty;
     servicePackInEffect = (instance.Properties["ServicePackInEffect"].Value != null && instance.Properties["ServicePackInEffect"].Value.ToString() != string.Empty)
                               ? instance.Properties["ServicePackInEffect"].Value.ToString().Trim()
                               : string.Empty;
     caption = (instance.Properties["Caption"].Value != null && instance.Properties["Caption"].Value.ToString() != string.Empty)
                               ? instance.Properties["Caption"].Value.ToString().Trim()
                               : string.Empty;
     cSName = (instance.Properties["CSName"].Value != null && instance.Properties["CSName"].Value.ToString() != string.Empty)
                               ? instance.Properties["CSName"].Value.ToString().Trim()
                               : string.Empty;
     installDate = (instance.Properties["InstallDate"].Value != null && instance.Properties["InstallDate"].Value != null && instance.Properties["InstallDate"].Value.ToString() != string.Empty)
                               ? instance.Properties["InstallDate"].Value.ToString().Trim()
                               : string.Empty;
     fixComments = (instance.Properties["FixComments"].Value != null && instance.Properties["FixComments"].Value.ToString() != string.Empty)
                               ? instance.Properties["FixComments"].Value.ToString().Trim()
                               : string.Empty;
     installedBy = (instance.Properties["InstalledBy"].Value != null && instance.Properties["InstalledBy"].Value.ToString() != string.Empty)
                               ? instance.Properties["InstalledBy"].Value.ToString().Trim()
                               : string.Empty;
     installedOn = (instance.Properties["InstalledOn"].Value != null && instance.Properties["InstalledOn"].Value.ToString() != string.Empty)
                               ? instance.Properties["InstalledOn"].Value.ToString().Trim()
                               : string.Empty;
     status = (instance.Properties["Status"].Value != null && instance.Properties["Status"].Value.ToString() != string.Empty)
                               ? instance.Properties["Status"].Value.ToString().Trim()
                               : string.Empty;
 }
开发者ID:hydrayu,项目名称:imobile-src,代码行数:33,代码来源:HotFixes.cs

示例3: Win32_SharesSearcher

 private static void Win32_SharesSearcher()
 {
     SelectQuery query = new SelectQuery("select * from Win32_Share where Name=\"" + sharename + "\"");
     using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
     {
         foreach (ManagementObject mo in searcher.Get())
         {
             foreach (PropertyData prop in mo.Properties)
             {
                 form.textBox1.AppendText(prop.Name + " = " + mo[prop.Name] + Environment.NewLine);                    }
                 //form.textBox1.AppendText(string.Format("Win32ShareName: {0} Description {1} Path {2} ", mo.Properties["Name"].Value, mo.Properties["Description"].Value, mo.Properties["Path"].Value) + Environment.NewLine);
         }
     }
     ManagementObject winShareP = new ManagementObject("root\\CIMV2", "Win32_Share.Name=\"" + sharename + "\"", null);
     ManagementBaseObject outParams = winShareP.InvokeMethod("GetAccessMask", null, null);
     form.textBox1.AppendText(String.Format("access Mask = {0:x}", outParams["ReturnValue"]) + Environment.NewLine);
     ManagementBaseObject inParams = winShareP.GetMethodParameters("SetShareInfo");
     form.textBox1.AppendText("SetShareInfor in parameters" + Environment.NewLine);
     foreach (PropertyData prop in inParams.Properties)
     {
         form.textBox1.AppendText(String.Format("PROP = {0}, TYPE = {1} ", prop.Name, prop.Type.ToString()) + Environment.NewLine);
     }
     Object access = inParams.GetPropertyValue("Access");
     //Stopped development here because ShareAFolder project exists. The rest of the development is there
     //Maybe should copy Sahare a Folder content to here at some point
 }
开发者ID:chughes-3,项目名称:WMI-Accessing,代码行数:26,代码来源:W32ShareSecurity.cs

示例4: DriveSN

 public static string DriveSN(string DriveLetter)
 {
     ManagementObject disk = new ManagementObject(String.Format("Win32_Logicaldisk='{0}'", DriveLetter));
     string VolumeName = disk.Properties["VolumeName"].Value.ToString();
     string SerialNumber = disk.Properties["VolumeSerialnumber"].Value.ToString();
     return SerialNumber.Insert(4, "-");
 }
开发者ID:mattocchi,项目名称:VS2010Commons,代码行数:7,代码来源:DiskUtils.cs

示例5: VideoController

 public VideoController(ManagementObject instance)
 {
     description = (instance.Properties["Description"].Value != null)
                       ? instance.Properties["Description"].Value.ToString().Trim()
                       : string.Empty;
     currentHorizontalResolution = (instance.Properties["CurrentHorizontalResolution"].Value !=
                                    null)
                                       ?
                                   instance.Properties["CurrentHorizontalResolution"].Value.
                                       ToString().Trim()
                                       : string.Empty;
     currentVerticalResolution = (instance.Properties["CurrentVerticalResolution"].Value != null)
                                     ?
                                 instance.Properties["CurrentVerticalResolution"].Value.ToString().
                                     Trim()
                                     : string.Empty;
     currentNumberOfColors = (instance.Properties["CurrentNumberOfColors"].Value != null)
                                 ?
                             instance.Properties["CurrentNumberOfColors"].Value.ToString().Trim()
                                 : string.Empty;
     videoProcessor = (instance.Properties["VideoProcessor"].Value != null)
                          ? instance.Properties["VideoProcessor"].Value.ToString().Trim()
                          : string.Empty;
     adapterRAM = (instance.Properties["AdapterRAM"].Value != null)
                      ? instance.Properties["AdapterRAM"].Value.ToString().Trim()
                      : string.Empty;
     installedDisplayDrivers = (instance.Properties["InstalledDisplayDrivers"].Value != null)
                                   ?
                               instance.Properties["InstalledDisplayDrivers"].Value.ToString().Trim
                                   ()
                                   : string.Empty;
     driverVersion = (instance.Properties["DriverVersion"].Value != null)
                         ? instance.Properties["DriverVersion"].Value.ToString().Trim()
                         : string.Empty;
 }
开发者ID:hydrayu,项目名称:imobile-src,代码行数:35,代码来源:VideoController.cs

示例6: GetVolumeSerial

 public static string GetVolumeSerial(string strDriveLetter)
 {
     if (strDriveLetter == "" || strDriveLetter == null) strDriveLetter = "C";
       ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + strDriveLetter + ":\"");
       disk.Get();
       return disk["VolumeSerialNumber"].ToString();
 }
开发者ID:PavelAlekseyuk,项目名称:Online-Processing-System-code-samples,代码行数:7,代码来源:Program.cs

示例7: DataStatistics

        int wnicIndex; //the index of the wireless network interface

        #endregion Fields

        #region Constructors

        public DataStatistics(Hashtable param)
        {
            SaveResult = PublicFuns.str2Int32((String)param["SaveResult"], 1);
            FileName = (String)param["FileName"];
            StatisticLevel = PublicFuns.str2Int32((String)param["StatisticLevel"], 0);
            wnicIndex = PublicFuns.str2Int32((String)param["WNICIndex"], 0);
            tempData = new StatData(param);

            hasWNIC = false;
            sysInfo = new SystemInfo();

            win32ProcessorObj = RetrieveManagementObject("Win32_Processor");
            processor.update(win32ProcessorObj);
            sysInfo.pro = processor;

            try
            {
                getSystemInfo();
                createSystemCounters();
                initLog();
            }
            catch (MyException ex)
            {
                throw ex;
            }
        }
开发者ID:hch-im,项目名称:ptopw,代码行数:32,代码来源:DataStatistics.cs

示例8: Disk

 public Disk(ManagementObject instance)
 {
     PropertyDataCollection.PropertyDataEnumerator enumerator = instance.Properties.GetEnumerator();
     while (enumerator.MoveNext())
     {
         Console.WriteLine(enumerator.Current.Name);
     }
     manufacturer = (instance.Properties["Manufacturer"].Value != null)
                        ? instance.Properties["Manufacturer"].Value.ToString().Trim()
                        : string.Empty;
     model = (instance.Properties["Model"].Value != null)
                 ? instance.Properties["Model"].Value.ToString().Trim()
                 : string.Empty;
     description = (instance.Properties["Description"].Value != null)
                       ? instance.Properties["Description"].Value.ToString().Trim()
                       : string.Empty;
     interfaceType = (instance.Properties["InterfaceType"].Value != null)
                         ? instance.Properties["InterfaceType"].Value.ToString().Trim()
                         : string.Empty;
     size = (instance.Properties["Size"].Value != null)
                ? instance.Properties["Size"].Value.ToString().Trim()
                : string.Empty;
     partitions = (instance.Properties["Partitions"].Value != null)
                      ? instance.Properties["Partitions"].Value.ToString().Trim()
                      : string.Empty;
     scsiBus = (instance.Properties["ScsiBus"].Value != null)
                   ? instance.Properties["ScsiBus"].Value.ToString().Trim()
                   : string.Empty;
     scsiTargetID = (instance.Properties["ScsiTargetID"].Value != null)
                        ? instance.Properties["ScsiTargetID"].Value.ToString().Trim()
                        : string.Empty;
     deviceID = (instance.Properties["DeviceID"].Value != null)
                    ? instance.Properties["DeviceID"].Value.ToString().Trim()
                    : string.Empty;
 }
开发者ID:hydrayu,项目名称:imobile-src,代码行数:35,代码来源:Disk.cs

示例9: Volume

        // Expects a Win32_DiskDrive object
        // http://msdn.microsoft.com/en-us/library/aa394132%28v=VS.85%29.aspx
        internal Volume(ManagementObject o)
        {
            if (o.ClassPath.ClassName != "Win32_DiskDrive")
                throw new ArgumentException (o.ClassPath.ClassName, "o");

            Uuid = o.Str ("PNPDeviceID");
            Name = o.Str ("Caption");

            // Get USB vendor/product ids from the associated CIM_USBDevice
            // This way of associating them (via a substring of the PNPDeviceID) is quite a hack; patches welcome
            var match = regex.Match (Uuid);
            if (match.Success) {
                string query = String.Format ("SELECT * FROM CIM_USBDevice WHERE DeviceID LIKE '%{0}'", match.Groups[1].Captures[0].Value);
                UsbDevice = HardwareManager.Query (query).Select (u => new UsbDevice (u)).FirstOrDefault ();
            }

            // Get MountPoint and more from the associated LogicalDisk
            // FIXME this assumes one partition for the device
            foreach (ManagementObject partition in o.GetRelated ("Win32_DiskPartition")) {
                foreach (ManagementObject disk in partition.GetRelated ("Win32_LogicalDisk")) {
                    //IsMounted = (bool)ld.GetPropertyValue ("Automount") == true;
                    //IsReadOnly = (ushort) ld.GetPropertyValue ("Access") == 1;
                    MountPoint = disk.Str ("Name") + "/";
                    FileSystem = disk.Str ("FileSystem");
                    Capacity = (ulong) disk.GetPropertyValue ("Size");
                    Available = (long)(ulong)disk.GetPropertyValue ("FreeSpace");
                    return;
                }
            }
        }
开发者ID:kelsieflynn,项目名称:banshee,代码行数:32,代码来源:Volume.cs

示例10: GetSnapshotData

        /// <summary>
        /// Gets the data for a given snapshot that belongs to the given virtual machine..
        /// </summary>
        /// <param name="virtualMachine">The virtual machine object.</param>
        /// <param name="snapshotName">The name of the snapshot that should be obtained.</param>
        /// <returns>The snapshot data object or <see langword="null" /> if no snapshot could be found.</returns>
        public static ManagementObject GetSnapshotData(ManagementObject virtualMachine, string snapshotName)
        {
            ManagementObjectCollection vmSettings = virtualMachine.GetRelated(
                "Msvm_VirtualSystemsettingData",
                "Msvm_PreviousSettingData",
                null,
                null,
                "SettingData",
                "ManagedElement",
                false,
                null);

            ManagementObject vmSetting = null;
            foreach (ManagementObject instance in vmSettings)
            {
                var name = (string)instance["ElementName"];
                if (string.Equals(snapshotName, name, StringComparison.Ordinal))
                {
                    vmSetting = instance;
                    break;
                }
            }

            return vmSetting;
        }
开发者ID:pvandervelde,项目名称:Sherlock,代码行数:31,代码来源:WmiUtility.cs

示例11: GetWorkGroupName

        public static string GetWorkGroupName()
        {
            string result = String.Empty;
            if (OSVersionPlatform.GetConcretePlatform() == PlatformID.MacOSX)
            {
                //OS X
                string configFilePath = @"/Library/Preferences/SystemConfiguration/com.apple.smb.server.plist";
                PlistParser parser = new PlistParser(configFilePath);
                result = parser["Workgroup"].ToString();
            }
            else if (OSVersionPlatform.GetGenericPlatform() == PlatformID.Unix)
            {
                //Linux
                string configFilePath = @"/etc/samba/smb.conf";
                IniFileParser parser = new IniFileParser(configFilePath);
                result = parser.GetValue("Global", "Workgroup");
            }
            else
            {
                //Windows
                using (ManagementObject managementObject = new ManagementObject(String.Format("Win32_ComputerSystem.Name='{0}'", Environment.MachineName)))
                {
                    object workgroup;
                    //Workgroup is NULL under XP
                    if (OSVersionPlatform.IsWindowsVistaOrHigher())
                        workgroup = managementObject["Workgroup"];
                    else
                        workgroup = managementObject["Domain"];

                    result = workgroup.ToString();
                }
            }
            return result;
        }
开发者ID:RomanySaad,项目名称:MultiMiner,代码行数:34,代码来源:LocalNetwork.cs

示例12: GetUptime

 public static string GetUptime()
 {
     ManagementObject mo = new ManagementObject(@"\\.\root\cimv2:[email protected]");
     DateTime lastBootUp = ManagementDateTimeConverter.ToDateTime(mo["LastBootUpTime"].ToString());
     TimeSpan temp = DateTime.Now.ToUniversalTime() - lastBootUp.ToUniversalTime();
     return temp.Days.ToString() + ":" + temp.Hours.ToString() + ":" + temp.Minutes.ToString() + ":" + temp.Seconds.ToString();
 }
开发者ID:GavinKenna,项目名称:Muroidea,代码行数:7,代码来源:Client.cs

示例13: RAM

 public RAM(CrystalFontz635 cf)
     : base(cf)
 {
     Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
     Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
     pfRAM = new PerformanceCounter("Memory", "Available MBytes");
     using (ManagementObject mo = new ManagementObject(@"Win32_ComputerSystem.Name=""" + Environment.MachineName + "\"")) {
         TotalInstalled = (ulong)mo["TotalPhysicalMemory"];
     }
     pfRAM.NextValue();
     LcdModule.ClearScreen();
     LcdModule.SetCursorPosition(0, 0);
     LcdModule.SendData(0, 0, string.Format("RAM USAGE (T:{0}Mb)", Math.Round(TotalInstalled / 1024.0 / 1024.0)).PadRight(20));
     LcdModule.SetCGRAM(0,
         new byte[] {
             0x3f,
             0x3f,
             0x3f,
             0x3f,
             0x3f,
             0x3f,
             0x3f,
             0x3f
         });
     time = new Stopwatch();
     time.Start();
 }
开发者ID:CryptonZylog,项目名称:cf635,代码行数:27,代码来源:RAM.cs

示例14: SetHostname

        public string SetHostname(string hostname)
        {
            var oldName = Environment.MachineName;
            _logger.Log("Old host name: " + oldName);
            _logger.Log("New host name: " + hostname);
            if (string.IsNullOrEmpty(hostname) || oldName.Equals(hostname, StringComparison.InvariantCultureIgnoreCase))
                return 0.ToString();

            using (var cs = new ManagementObject(@"Win32_Computersystem.Name='" + oldName + "'"))
            {
                cs.Get();
                var inParams = cs.GetMethodParameters("Rename");
                inParams.SetPropertyValue("Name", hostname);
                var methodOptions = new InvokeMethodOptions(null, TimeSpan.MaxValue);
                var outParams = cs.InvokeMethod("Rename", inParams, methodOptions);
                if (outParams == null)
                    return 1.ToString();

                var renameResult = Convert.ToString(outParams.Properties["ReturnValue"].Value);
                //Restart in 10 secs because we want finish current execution and write response back to Xenstore.
                if ("0".Equals(renameResult))
                    Process.Start(@"shutdown.exe", @"/r /t 10 /f /d p:2:4");
                return renameResult;
            }
        }
开发者ID:kashivreddy,项目名称:openstack-guest-agents-windows-xenserver,代码行数:25,代码来源:SetHostnameAction.cs

示例15: GetImportedPvm

        GetImportedPvm(
            ManagementBaseObject outputParameters)
        {
            ManagementObject pvm = null;
            ManagementScope scope = new ManagementScope(@"root\virtualization\v2");

            if (WmiUtilities.ValidateOutput(outputParameters, scope))
            {
                if ((uint)outputParameters["ReturnValue"] == 0)
                {
                    pvm = new ManagementObject((string)outputParameters["ImportedSystem"]);
                }
                
                if ((uint)outputParameters["ReturnValue"] == 4096)
                {
                    using (ManagementObject job = 
                        new ManagementObject((string)outputParameters["Job"]))
                    using (ManagementObjectCollection pvmCollection = 
                        job.GetRelated("Msvm_PlannedComputerSystem",
                            "Msvm_AffectedJobElement", null, null, null, null, false, null))
                    {
                        pvm = WmiUtilities.GetFirstObjectFromCollection(pvmCollection);
                    }

                }
            }

            return pvm;
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:29,代码来源:ImportUtilities.cs


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