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


C# ManagementObject.Get方法代码示例

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


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

示例1: CleanDirectory

        public bool CleanDirectory(DirectoryInfo dirInfo, string[] folderNames)
        {
            //get list of directories
            DirectoryInfo[] dirs = dirInfo.GetDirectories();

            //loop each
            foreach (DirectoryInfo dir in dirs)
            {
                bool istarget = false;
                foreach (string fname in folderNames)
                {
                    istarget = (dir.Name == fname);
                    if (istarget) break;
                }

                if (istarget)
                {
                    //dir.Attributes = FileAttributes.Normal;
                    //Directory.Delete(dir.FullName, true);
                    using (ManagementObject mo = new ManagementObject(String.Format("win32_Directory.Name='{0}'", dir.FullName)))
                    {
                        mo.Get();
                        ManagementBaseObject outParams = mo.InvokeMethod("Delete", null, null);
                        if (Convert.ToInt32(outParams.Properties["ReturnValue"].Value) != 0) return false;
                    }
                }
                else if (!CleanDirectory(dir, folderNames))
                    return false;
            }

            return true;
        }
开发者ID:rebootd,项目名称:csinctools,代码行数:32,代码来源:Cleaner.cs

示例2: readHDD_ID

		public void readHDD_ID()
        {
            string drive = Path.GetPathRoot(Environment.SystemDirectory); //"C";
            drive = drive.Substring(0, 1);
            ManagementObject dsk = new ManagementObject(
                @"win32_logicaldisk.deviceid=""" + drive + @":""");
            dsk.Get();
            string volumeSerial = dsk["VolumeSerialNumber"].ToString();

            HDD_ID = volumeSerial;
        }
开发者ID:andri2908,项目名称:RoyalPetz,代码行数:11,代码来源:globalCryptographyMethod.cs

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

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

示例5: GetUniqueSystemIdentifier

        private static String GetUniqueSystemIdentifier()
        {
            var search = new ManagementObjectSearcher("SELECT * FROM Win32_baseboard");
            var mobos = search.Get();
            var motherboardSerial ="";
            foreach (var m in mobos)
            {
                motherboardSerial = m["SerialNumber"].ToString(); // ProcessorID if you use Win32_CPU
            }
            String path = Path.GetPathRoot(Environment.SystemDirectory);
            String drive = path.Split(':')[0];
            ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + drive + @":""");
            dsk.Get();
            string volumeSerial = dsk["VolumeSerialNumber"].ToString();
           
            string cpuInfo = string.Empty;
            ManagementClass mc = new ManagementClass("win32_processor");
            ManagementObjectCollection moc = mc.GetInstances();

            foreach (ManagementObject mo in moc)
            {
                if (cpuInfo == "")
                {
                    //Get only the first CPU's ID
                    cpuInfo = mo.Properties["processorID"].Value.ToString();
                    break;
                }
            }

            return cpuInfo + motherboardSerial + volumeSerial;
        }
开发者ID:kaizenx,项目名称:securebox,代码行数:31,代码来源:Securebox.cs

示例6: VolumeManager_NewSession

        void VolumeManager_NewSession(VolumeSession rpSession)
        {
            var rHostProcessID = Process.GetCurrentProcess().Id;
            int? rProcessID = rpSession.ProcessID;

            var rIsBrowserProcess = false;

            while (rProcessID.HasValue)
                using (var rManagementObject = new ManagementObject($"Win32_Process.Handle='{rProcessID.Value}'"))
                    try
                    {
                        rManagementObject.Get();
                        rProcessID = Convert.ToInt32(rManagementObject["ParentProcessId"]);

                        if (rProcessID == rHostProcessID)
                        {
                            rIsBrowserProcess = true;
                            break;
                        }
                    }
                    catch (ManagementException e) when (e.ErrorCode == ManagementStatus.NotFound)
                    {
                        rProcessID = null;
                    }

            if (!rIsBrowserProcess)
                return;

            Volume?.Dispose();
            Volume = new BrowserVolume(rpSession);

            VolumeManager.Instance.NewSession -= VolumeManager_NewSession;
        }
开发者ID:CodeForCSharp,项目名称:KanColleInspector,代码行数:33,代码来源:GameController.cs

示例7: Main

        static void Main()
        {
            DirectoryInfo currentDir = new DirectoryInfo(Environment.CurrentDirectory);
            string path = string.Format("win32_logicaldisk.deviceid=\"{0}\"",
                currentDir.Root.Name.Replace("\\", ""));
            ManagementObject disk = new ManagementObject(path);
            disk.Get();

            String serial = disk["VolumeSerialNumber"].ToString();
            Conexion_MSS conexion = new Conexion_MSS("null", "null", "Requerimientos", 0);
            conexion.conexion.Open();
            conexion.cmd = new System.Data.SqlClient.SqlCommand("Select usuario from Cuentas where ID='" + serial + "'", conexion.conexion);
            conexion.reader = conexion.cmd.ExecuteReader();
            List<String> cuentas = new List<string>();
            while (conexion.reader.Read())
            {
                cuentas.Add(conexion.reader[0].ToString());
            }
            conexion.reader.Close();
            conexion.conexion.Close();

            if (cuentas.Count() > 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Cuentas(serial,cuentas));

            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Login(serial));
            }
        }
开发者ID:aifos29,项目名称:Requerimientos,代码行数:35,代码来源:Program.cs

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

示例9: GetHDInfo

 protected string GetHDInfo()
 {
     string drive = "C";
     ManagementObject dsk = new ManagementObject(
         @"win32_logicaldisk.deviceid=""" + drive + @":""");
     dsk.Get();
     return dsk["VolumeSerialNumber"].ToString();
 }
开发者ID:ddksaku,项目名称:rzr,代码行数:8,代码来源:LicenseService.cs

示例10: DiskSize

 //取得disk大小
 public static UInt64 DiskSize(string path, string propertys)
 {
     ManagementObject size = new ManagementObject("win32_logicaldisk.deviceid=" + path);
     size.Get();
     UInt64 b = 1024;
     UInt64 a = (Convert.ToUInt64(size[propertys]) / b) / b;
     return a;
 }
开发者ID:dalinhuang,项目名称:appcollection,代码行数:9,代码来源:FileHandle.cs

示例11: GetId

        public static string GetId()
        {
            ManagementObject dsk = new ManagementObject("win32_logicaldisk.deviceid=\"C:\"");
            dsk.Get();

            string a = dsk["VolumeSerialNumber"].ToString();

            return "_" + Md5Encrypt("+meepo"+a+"mootoo") + "_";
        }
开发者ID:mootoomeepo,项目名称:mootoo.meepo,代码行数:9,代码来源:GetCpuId.cs

示例12: GetParentProcess

 private static int GetParentProcess(int Id)
 {
     int parentPid = 0;
     using (ManagementObject mo = new ManagementObject("win32_process.handle='" + Id.ToString() + "'"))
     {
         mo.Get();
         parentPid = Convert.ToInt32(mo["ParentProcessId"]);
     }
     return parentPid;
 }
开发者ID:virajs,项目名称:monoscape,代码行数:10,代码来源:ProcessManager.cs

示例13: EnterLicense_Load

 private void EnterLicense_Load(object sender, EventArgs e)
 {
     ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
     ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
     disk.Get();
     string temp = Des.EncryptDES(disk.GetPropertyValue("VolumeSerialNumber").ToString(), Des.ConstKey);
     tempStr = Des.EncryptDES(Des.EncryptDES(disk.GetPropertyValue("VolumeSerialNumber").ToString(), Des.ConstKey), Des.ConstKey);
     this.txtOnlyMsg.Text = temp.Trim();
     this.txtLicense.Text = DealXml.ReadSysConfig("appSettings", "license");
 }
开发者ID:Maginx,项目名称:MallProject,代码行数:10,代码来源:EnterLicense.cs

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

示例15: PerformanceCounters

 public PerformanceCounters()
 {
     InitializeComponent();
     mObject = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
     mObject.Get();
     cpuCounter = new PerformanceCounter("Processor Information", "% Processor Time");
     performanceCounterChart.MarqueeAnimationSpeed = 1;
     Style = ProgressBarStyle.Blocks;
     ScaleMode = SpPerfChart.ScaleMode.Absolute;
 }
开发者ID:Behzadkhosravifar,项目名称:MakeClassSchedule,代码行数:10,代码来源:PerformanceCounters.cs


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