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


C# ManagementObject.Dispose方法代码示例

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


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

示例1: CPUSpeed

 public static uint CPUSpeed()
 {
     ManagementObject mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
     uint sp = (uint)(mo["CurrentClockSpeed"]);
     mo.Dispose();
     return sp;
 }
开发者ID:wushian,项目名称:Stacks,代码行数:7,代码来源:Program.cs

示例2: CPUSpeed

 public string CPUSpeed()
 {
     ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
     uint sp = (uint)(Mo["CurrentClockSpeed"]);
     Mo.Dispose();
     decimal speed = Convert.ToDecimal(sp);
     speed = Math.Round(speed / 1000, 1);
     string speedString = speed + " Ghz";
     return speedString;
 }
开发者ID:Rooster212,项目名称:LCDStudio-Csharp-Example,代码行数:10,代码来源:Class1.cs

示例3: CVolumeSerial

        /// <summary>
        /// Returns the HDD volume of c:
        /// </summary>
        /// <returns></returns>
        private static string CVolumeSerial()
        {
            var disk = new ManagementObject(@"win32_logicaldisk.deviceid=""c:""");
            disk.Get();

            string volumeSerial = disk["VolumeSerialNumber"].ToString();
            disk.Dispose();

            return volumeSerial;
        }
开发者ID:smosgin,项目名称:labofthings,代码行数:14,代码来源:Utils.cs

示例4: getVolumeSerial

        private string getVolumeSerial(string drive)
        {
            ManagementObject disk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + drive + @":""");
            disk.Get();

            string volumeSerial = disk["VolumeSerialNumber"].ToString();
            disk.Dispose();

            return volumeSerial;
        }
开发者ID:ChrisPea,项目名称:TuningSuites,代码行数:10,代码来源:HWID.cs

示例5: getVolumeSerial

        private string getVolumeSerial(string drive)
        {
            ManagementObject disk = new ManagementObject(string.Format("{0}{1}{2}", @"win32_logicaldisk.deviceid=""", drive, @":"""));
            disk.Get();

            string volumeSerial = disk["VolumeSerialNumber"].ToString();
            disk.Dispose();

            return volumeSerial;
        }
开发者ID:BjkGkh,项目名称:Azure2,代码行数:10,代码来源:Main.cs

示例6: CpuSpeed

        public static uint CpuSpeed()
        {
#if !mono
            var mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
            var sp = (uint) (mo["CurrentClockSpeed"]);
            mo.Dispose();
            return sp;
#else
            return 0;
#endif
        }
开发者ID:pdoh00,项目名称:akka.net,代码行数:11,代码来源:Program.cs

示例7: CPUSpeed

        public static uint CPUSpeed()
        {
#if !mono
            ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
            uint sp = (uint)(Mo["CurrentClockSpeed"]);
            Mo.Dispose();
            return sp;
#else
            return 0;
#endif
        }
开发者ID:Badmoonz,项目名称:akka.net,代码行数:11,代码来源:Program.cs

示例8: GetData

        /// <summary>
        /// Get the data from the local machine and write it to the storage location
        /// </summary>
        public static void GetData()
        {
            int cpuSpeedMHz;
            long memoryBytes;
            string operatingSystemVersion;

            StorageManager.InitializeMachineStorage();

            string data = string.Empty;

            try
            {
                // get CPU speed in MHz
                ManagementObject moProcessor = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
                cpuSpeedMHz = Convert.ToInt32(moProcessor["CurrentClockSpeed"]);
                moProcessor.Dispose();
                StorageManager.Write(SpecificationSource.LocalMachine, SpecificationType.CPU, cpuSpeedMHz.ToString());

                // get RAM size in bytes
                ManagementClass mcRAM = new ManagementClass("Win32_ComputerSystem");
                ManagementObjectCollection mocRAM = mcRAM.GetInstances();
                foreach (ManagementObject moRAM in mocRAM)
                {
                    memoryBytes = Convert.ToInt64(moRAM["TotalPhysicalMemory"]);
                    moRAM.Dispose();
                    StorageManager.Write(SpecificationSource.LocalMachine, SpecificationType.RAM, memoryBytes.ToString());
                }

                DriveInfo[] drives = DriveInfo.GetDrives();
                foreach (DriveInfo drive in drives)
                {
                    if (drive.Name == @"C:\")
                    {
                        StorageManager.Write(SpecificationSource.LocalMachine, SpecificationType.FreeDiskSpace, drive.AvailableFreeSpace.ToString());
                    }
                }

                // get screen resolution
                Rectangle resolution = Screen.PrimaryScreen.Bounds;
                StorageManager.Write(SpecificationSource.LocalMachine, SpecificationType.ScreenResolution, resolution.Width.ToString());
                StorageManager.Write(SpecificationSource.LocalMachine, SpecificationType.ScreenResolution, resolution.Height.ToString());

                // get OS major and minor version numbers
                operatingSystemVersion = Environment.OSVersion.Version.Major.ToString() + "." +
                    Environment.OSVersion.Version.Minor.ToString();
                StorageManager.Write(SpecificationSource.LocalMachine, SpecificationType.OSVersion, operatingSystemVersion);
            }
            catch (Exception e)
            {
                throw new ApplicationException("An error has occoured.  Error report follows:" + e.Message);
            }
        }
开发者ID:charleshepner,项目名称:CompassAppAssesmentTool,代码行数:55,代码来源:NWAssessment.cs

示例9: GetCPUSpeed

        public uint GetCPUSpeed()
        {
            uint result = 0;
            ManagementObject mo = null;

            try
            {
                mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
                result = (uint)mo["MaxClockSpeed"];
            }
            catch { }
            finally
            {
                if (mo != null)
                    mo.Dispose();
            }

            return result;
        }
开发者ID:HomeSen,项目名称:BFP4F-Troubleshooting,代码行数:19,代码来源:SystemHelper.cs

示例10: DeleteShare

        /// <summary>
        /// Deletes the share.
        /// </summary>
        public void DeleteShare()
        {
            ManagementBaseObject outParams = null;
            ManagementObject shareInstance = null;

            try
            {
                shareInstance = new ManagementObject(@"root\cimv2:Win32_Share.Name='" + this.shareName + "'");
                outParams = shareInstance.InvokeMethod("Delete", null, null);

                if ((uint)outParams["ReturnValue"] != 0)
                {
                    throw new WindowsShareException("Unable to delete share. Win32_Share.Delete Error Code: " + outParams["ReturnValue"]);
                }
            }
            catch (Exception ex)
            {
                throw new WindowsShareException("Unable to delete share: " + this.shareName, ex);
            }
            finally
            {
                if (shareInstance != null)
                {
                    shareInstance.Dispose();
                }

                if (outParams != null)
                {
                    outParams.Dispose();
                }
            }
        }
开发者ID:mihaibuzgau,项目名称:cf-windows-extensions,代码行数:35,代码来源:WindowsShare.cs

示例11: AddSharePermission

        /// <summary>
        /// Adds the share permissions.
        /// </summary>
        /// <param name="accountName">Name of the account.</param>
        public void AddSharePermission(string accountName)
        {
            ManagementObject trustee = null;
            ManagementObject ace = null;
            ManagementObject win32LogicalSecuritySetting = null;
            ManagementObject share = null;
            ManagementBaseObject getSecurityDescriptorReturn = null;
            ManagementBaseObject securityDescriptor = null;

            try
            {
                //// Not necessary
                //// NTAccount ntAccount = new NTAccount(accountName);
                //// SecurityIdentifier sid = (SecurityIdentifier)ntAccount.Translate(typeof(SecurityIdentifier));
                //// byte[] sidArray = new byte[sid.BinaryLength];
                //// sid.GetBinaryForm(sidArray, 0);

                trustee = new ManagementClass(new ManagementPath("Win32_Trustee"), null);
                trustee["Name"] = accountName;
                //// trustee["SID"] = sidArray;

                ace = new ManagementClass(new ManagementPath("Win32_Ace"), null);
                //// Permissions mask http://msdn.microsoft.com/en-us/library/windows/desktop/aa394186(v=vs.85).aspx
                ace["AccessMask"] = 0x1F01FF;
                //// ace["AccessMask"] = 0x1FF;
                ace["AceFlags"] = 3;
                ace["AceType"] = 0;
                ace["Trustee"] = trustee;

                win32LogicalSecuritySetting = new ManagementObject(@"root\cimv2:Win32_LogicalShareSecuritySetting.Name='" + this.shareName + "'");

                getSecurityDescriptorReturn = win32LogicalSecuritySetting.InvokeMethod("GetSecurityDescriptor", null, null);

                if ((uint)getSecurityDescriptorReturn["ReturnValue"] != 0)
                {
                    throw new WindowsShareException("Unable to add share permission. Error Code: " + getSecurityDescriptorReturn["ReturnValue"]);
                }

                securityDescriptor = getSecurityDescriptorReturn["Descriptor"] as ManagementBaseObject;
                ManagementBaseObject[] dacl = securityDescriptor["DACL"] as ManagementBaseObject[];

                if (dacl == null)
                {
                    dacl = new ManagementBaseObject[] { ace };
                }
                else
                {
                    Array.Resize(ref dacl, dacl.Length + 1);
                    dacl[dacl.Length - 1] = ace;
                }

                securityDescriptor["DACL"] = dacl;

                share = new ManagementObject(@"root\cimv2:Win32_Share.Name='" + this.shareName + "'");
                uint setShareInfoReturn = (uint)share.InvokeMethod("SetShareInfo", new object[] { null, null, securityDescriptor });

                if (setShareInfoReturn != 0)
                {
                    throw new WindowsShareException("Unable to add share permission. Error code: " + setShareInfoReturn.ToString(CultureInfo.CurrentCulture));
                }
            }
            catch (Exception ex)
            {
                throw new WindowsShareException("Unable to add share permission", ex);
            }
            finally
            {
                if (trustee != null)
                {
                    trustee.Dispose();
                }

                if (ace != null)
                {
                    ace.Dispose();
                }

                if (win32LogicalSecuritySetting != null)
                {
                    win32LogicalSecuritySetting.Dispose();
                }

                if (getSecurityDescriptorReturn != null)
                {
                    getSecurityDescriptorReturn.Dispose();
                }

                if (securityDescriptor != null)
                {
                    securityDescriptor.Dispose();
                }

                if (share != null)
                {
                    share.Dispose();
                }
//.........这里部分代码省略.........
开发者ID:mihaibuzgau,项目名称:cf-windows-extensions,代码行数:101,代码来源:WindowsShare.cs

示例12: CheckFreeSpace

        private void CheckFreeSpace(string drive)
        {
            bool sleep_req = false;
              do
              {
            if (sleep_req)
            {
              System.Threading.Thread.Sleep(15 * 1000);
              sleep_req = false;
            }
            try
            {
              ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive + "\"");
              disk.Get();
              if (Convert.ToInt64(disk["FreeSpace"]) < 5242880)
              {
            SendMsg(disk["FreeSpace"].ToString());
            throw new ManagementException();
              }
              disk.Dispose();
            }
            catch (ManagementException mex)
            {
              EventLog.WriteEntry("Out of disk space error: ", "CCreator Creator: " + mex.ToString(), EventLogEntryType.Warning);
              EventLog.WriteEntry("Sleeping for 15 seconds...", "CCreator Creator");
              sleep_req = true;
            }
              } while (sleep_req);

              GC.Collect();
              GC.WaitForPendingFinalizers();
              GC.Collect();
        }
开发者ID:dolphy17,项目名称:csender,代码行数:33,代码来源:CSender.cs

示例13: cpuSpeed

 private void cpuSpeed()
 {
     try
     {
         ManagementObject searcher = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
         currentSpeed = Convert.ToInt32((searcher["CurrentClockSpeed"]));
         cpuSpeedQ.Enqueue(currentSpeed);
         Console.WriteLine("Speed MHZ:" + currentSpeed.ToString());
         if (cpuSpeedQ.Count > 133) cpuSpeedQ.Dequeue();
         searcher.Dispose();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
开发者ID:Tylerflick,项目名称:G-Series_System_Monitor,代码行数:16,代码来源:Model.cs

示例14: CPUSpeed

 private uint CPUSpeed()
 {
     ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
     uint sp = (uint)(Mo["CurrentClockSpeed"]);
     Mo.Dispose();
     return sp;
 }
开发者ID:bajracha,项目名称:thesis,代码行数:7,代码来源:Form1.cs

示例15: CreateHardwareProfile

        /// <summary>Generates an XML containing user hardware information.</summary>
        /// <param name="graphics">GraphicsDevice so that we can easily probe for the GPU</param>
        public void CreateHardwareProfile(GraphicsDevice graphics)
        {
            //Check to see if the Tree structure has been setup
            if (!Directory.Exists(m_Directories[ExperiaDirectories.Configs]))
            {
                Directory.CreateDirectory(m_Directories[ExperiaDirectories.Configs]);
            }

            XmlWriterSettings settings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true };

            //If the File Exists lets check to make sure the hardware is the same
            bool makeFile = false;
            if (File.Exists(m_Paths[ExperiaFiles.HardwareProfile]))
            {
                XmlReaderSettings readerSettings = new XmlReaderSettings { IgnoreComments = true, IgnoreWhitespace = true };
                XmlReader reader = XmlReader.Create(m_Paths[ExperiaFiles.HardwareProfile], readerSettings);

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            switch (reader.Name)
                            {
                                case "Machine":
                                    if (reader.GetAttribute("HWGUID") != ExperiaHelper.Instance.HardwareGuidGen(graphics).ToString())
                                        makeFile = true;
                                    break;
                            }
                            break;
                    }
                }

                reader.Close();
            }

            //This takes a bit so lets make sure that we even need to make the doc
            if (!File.Exists(m_Paths[ExperiaFiles.HardwareProfile]) || makeFile)
            {

                XmlWriter writer = XmlWriter.Create(m_Paths[ExperiaFiles.HardwareProfile], settings);

                //OS Info
                XmlWriteAttributeElement(writer, "Machine", "HWGUID", ExperiaHelper.Instance.HardwareGuidGen(graphics).ToString());
                XmlWriteAttributeElement(writer, "OS", "Is64Bit", Environment.Is64BitOperatingSystem.ToString(), Environment.OSVersion.ToString());

                //Processor Write
                ManagementObject processorObject = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
                Dictionary<string, string> processorInfo = new Dictionary<string, string>();
                processorInfo.Add("Count", Environment.ProcessorCount.ToString());
                processorInfo.Add("Clock", processorObject["CurrentClockSpeed"].ToString());
                processorInfo.Add("MaxClock", processorObject["MaxClockSpeed"].ToString());
                processorInfo.Add("L2", processorObject["L2CacheSize"].ToString());
                processorInfo.Add("L3", processorObject["L3CacheSize"].ToString());
                XmlWriteAttributeElement(writer, "Processor", processorInfo, processorObject["Name"].ToString());
                processorObject.Dispose();

                //Memory Info
                XmlWriteAttributeElement(writer, "RAM", "Bytes", new ComputerInfo().TotalPhysicalMemory.ToString());
                writer.WriteEndElement();

                //Network Info
                Dictionary<string, string> networkInfo = new Dictionary<string, string>();
                networkInfo.Add("ComputerName", Environment.MachineName);
                networkInfo.Add("UserName", Environment.UserName);
                XmlWriteAttributeElement(writer, "Network", networkInfo, false);
                networkInfo.Clear();
                //Network Adapter Info
                for(int i = 0; i < NetworkInterface.GetAllNetworkInterfaces().Length; i++)
                {
                    if (NetworkInterface.GetAllNetworkInterfaces()[i].OperationalStatus == OperationalStatus.Up)
                    {
                        networkInfo.Add("Name", NetworkInterface.GetAllNetworkInterfaces()[i].Description);
                        networkInfo.Add("Speed", NetworkInterface.GetAllNetworkInterfaces()[i].Speed.ToString());
                        networkInfo.Add("MAC", NetworkInterface.GetAllNetworkInterfaces()[i].GetPhysicalAddress().ToString());
                        XmlWriteAttributeElement(writer, "Adapter", networkInfo, false);
                        writer.WriteEndElement();
                        networkInfo.Clear();
                    }
                }
                writer.WriteEndElement();

                //Gpu Info
                Dictionary<string, string> gpuAttributes = new Dictionary<string, string>();
                gpuAttributes.Add("ID", graphics.Adapter.DeviceId.ToString());
                gpuAttributes.Add("VendorID", graphics.Adapter.VendorId.ToString());
                gpuAttributes.Add("SystemID", graphics.Adapter.SubSystemId.ToString());
                gpuAttributes.Add("Revision", graphics.Adapter.Revision.ToString());
                gpuAttributes.Add("HiDefCapable", graphics.Adapter.IsProfileSupported(GraphicsProfile.HiDef).ToString());
                XmlWriteAttributeElement(writer, "GPU", gpuAttributes, graphics.Adapter.Description);
                //Gpu Desktop Res
                Dictionary<string, string> gpuDesktopRes = new Dictionary<string, string>();
                gpuDesktopRes.Add("X", graphics.Adapter.CurrentDisplayMode.Width.ToString());
                gpuDesktopRes.Add("Y", graphics.Adapter.CurrentDisplayMode.Height.ToString());
                XmlWriteAttributeElement(writer, "DesktopResolution", gpuDesktopRes);

                //Close out the file
                XmlClose(writer);
//.........这里部分代码省略.........
开发者ID:rbrito89,项目名称:Teardrop,代码行数:101,代码来源:FileIO.cs


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