示例#1
0
        static void Main(string[] args)
        {
            WqlObjectQuery query = new WqlObjectQuery(
                "SELECT * FROM Win32_BootConfiguration");
            ManagementObjectSearcher find =
                new ManagementObjectSearcher(query);

            foreach (ManagementObject mo in find.Get())
            {
                Console.WriteLine("Boot directory with files required for booting." + mo["BootDirectory"]);
                Console.WriteLine("Description." + mo["Description"]);
                Console.WriteLine("Directory with temporary files for booting." + mo["ScratchDirectory"]);
                Console.WriteLine("Directory with temporary files." + mo["TempDirectory"]);
            }
        }
            // This function is acquired from StackOverflow:
            // http://stackoverflow.com/questions/2728578/how-to-get-phyiscal-path-of-windows-service-using-net
            // (with a bit of more careful object disposal)
            public static string GetPathOfService(string serviceName)
            {
                WqlObjectQuery wqlObjectQuery = new WqlObjectQuery(string.Format("SELECT * FROM Win32_Service WHERE Name like '{0}%'", serviceName));

                using (ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(wqlObjectQuery))
                    using (ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get())
                    {
                        foreach (ManagementObject managementObject in managementObjectCollection)
                        {
                            return(managementObject.GetPropertyValue("PathName").ToString());
                        }
                    }

                return(null);
            }
示例#3
0
        static void Main(string[] args)
        {
            WqlObjectQuery query = new WqlObjectQuery(
                "SELECT * FROM Win32_ComputerSystem");
            ManagementObjectSearcher find =
                new ManagementObjectSearcher(query);

            // Новое имя компьютера
            object[] methodArgs = { "New name" };
            foreach (ManagementObject mo in find.Get())
            {
                // Вызвать метод Rename
                mo.InvokeMethod("Rename", methodArgs);
            }
        }
示例#4
0
        /// <summary>
        /// 获取特定磁盘信息
        /// </summary>
        /// <param name="driverId"></param>
        /// <returns></returns>
        private List <DriveInfo> GetLogicalDrives(char driverId)
        {
            var drives   = new List <DriveInfo>();
            var wmiquery = new WqlObjectQuery("SELECT * FROM Win32_LogicalDisk WHERE DeviceID = ’" + driverId + ":’");
            var wmifind  = new ManagementObjectSearcher(wmiquery);

            foreach (var disk in wmifind.Get())
            {
                if (int.Parse(disk["DriveType"].ToString()) == (int)DriveType.Fixed)
                {
                    drives.Add(new DriveInfo(disk["Name"].ToString(), Math.Round(long.Parse(disk["Size"].ToString()) / 1024.00 / 1024.00 / 1024.00, 2) + "GB", Math.Round(long.Parse(disk["FreeSpace"].ToString()) / 1024.00 / 1024.00 / 1024.00, 2) + "GB"));
                }
            }
            return(drives);
        }
示例#5
0
        ///
        /// 获取特定分区信息
        ///
        /// 盘符
        public List <DiskInfo> GetLogicalDrives(char DriverID)
        {
            List <DiskInfo>          drives   = new List <DiskInfo>();
            WqlObjectQuery           wmiquery = new WqlObjectQuery("SELECT * FROM Win32_LogicalDisk WHERE DeviceID = ’" + DriverID + ":’");
            ManagementObjectSearcher wmifind  = new ManagementObjectSearcher(wmiquery);

            foreach (ManagementObject disk in wmifind.Get())
            {
                if (int.Parse(disk["DriveType"].ToString()) == (int)DriveType.Fixed)
                {
                    drives.Add(new DiskInfo(disk["Name"].ToString(), long.Parse(disk["Size"].ToString()), long.Parse(disk["FreeSpace"].ToString())));
                }
            }
            return(drives);
        }
示例#6
0
        static void Main(string[] args)
        {
            // Получить настройки рабочего стола
            WqlObjectQuery query = new WqlObjectQuery(
                "SELECT * FROM Win32_Desktop WHERE Name = '.Default'");
            ManagementObjectSearcher find =
                new ManagementObjectSearcher(query);

            foreach (ManagementObject mo in find.Get())
            {
                // Значения могут быть изменены
                // в реестре "HKEY_CURRENT_USER\Control Panel\Desktop"
                Console.WriteLine("Width of window borders." +
                                  mo["BorderWidth"]);
                Console.WriteLine("ALT+TAB task switching allowed." +
                                  mo["CoolSwitch"]);
                // Значения в мс
                Console.WriteLine("Lenght of time between cursor blincks. " +
                                  mo["CursorBlinkRate"]);
                Console.WriteLine("Show content of windows when are draged." +
                                  mo["DragFullWindows"]);
                Console.WriteLine("Grid settings for dragging windows." +
                                  mo["GridGranularity"]);
                Console.WriteLine("Grid settings for icon spacing. " +
                                  mo["IconSpacing"]);
                Console.WriteLine("Font used for the names of icons." +
                                  mo["IconTitleFaceName"]);
                Console.WriteLine("Icon ront size. " + mo["IconTitleSize"]);
                Console.WriteLine("Wrapping of icon title." +
                                  mo["IconTitleWrap"]);
                Console.WriteLine("Name of the desktop profile." +
                                  mo["Name"]);
                Console.WriteLine("Screen saver is active." +
                                  mo["ScreenSaverActive"]);
                Console.WriteLine("Name of the screen saver executable." +
                                  mo["ScreenSaverExecutable"]);
                Console.WriteLine("Is screen saver protected with password." +
                                  mo["ScreenSaverSecure"]);
                Console.WriteLine("Time to pass to activate screen saver." +
                                  mo["ScreenSaverTimeout"]);
                Console.WriteLine("File name for desktop background." +
                                  mo["Wallpaper"]);
                Console.WriteLine("Wallpaper fills entire screen." +
                                  mo["WallpaperStretched"]);
                Console.WriteLine("Wallpaper is tiled." +
                                  mo["WallpaperTiled"]);
            }
        }
示例#7
0
        static List <Target> GetActiveProcessList(Logit log)
        {
            List <Target>            activeList = new List <Target>();
            WqlObjectQuery           w          = new WqlObjectQuery("Select * from Win32_Process");
            ManagementObjectSearcher mos        = new ManagementObjectSearcher(w);

            foreach (ManagementObject mo in mos.Get())
            {
                try
                {
                    Target po = new Target();
                    po.PID = Convert.ToInt32(mo.Properties["ProcessID"].Value.ToString());
                    try
                    {
                        po.StartTime = convertFromWmiToDotNetDateTime(mo.Properties["CreationDate"].Value.ToString());
                    }
                    catch { }
                    string pathName = "NA";
                    if (po.PID == 0)
                    {
                        pathName = "System Idle Process";
                    }
                    else if (po.PID == 4)
                    {
                        pathName = "System";
                    }
                    else
                    {
                        try
                        {
                            pathName = mo.Properties["ExecutablePath"].Value.ToString();
                        }
                        catch
                        {
                            pathName = mo.Properties["Caption"].Value.ToString();  // can fail when attempting to get extended process info on protected processes, until i do, we use the process name as path
                        }
                    }
                    po.Name = mo.Properties["Caption"].Value.ToString().ToLower();
                    po.Path = pathName.ToLower();
                    activeList.Add(po);
                }
                catch (Exception ex)
                {
                    log.Append("Warning:  could not get details on process: " + mo.Path, LogVerboseLevel.Normal);
                }
            }
            return(activeList);
        }
示例#8
0
 public static void getHDDInfo()
 {
     foreach (System.IO.DriveInfo label in System.IO.DriveInfo.GetDrives())
     {
         if (label.IsReady)
         {
             WqlObjectQuery q = new WqlObjectQuery("SELECT * FROM Win32_DiskDrive");
             ManagementObjectSearcher res = new ManagementObjectSearcher(q);
             foreach (ManagementObject o in res.Get())
             {
                 HDD = label.Name + " " + label.TotalSize / 1000000000 + "GB, " + o["Caption"].ToString();
                 HDDList.Add(HDD);
             }
         }
     }
 }
        private void GetPhysicalDriveList()
        {
            var query = new WqlObjectQuery("SELECT * FROM Win32_DiskDrive");

            using (var searcher = new ManagementObjectSearcher(query))
            {
                physicalDiskList = searcher.Get()
                                   .OfType <ManagementObject>()
                                   .ToList();

                var ds = physicalDiskList.Select(o => $"{o.Properties["DeviceID"].Value} | {o.Properties["Model"].Value} | {(Double.Parse(o.Properties["Size"].Value.ToString())/1073741824).ToString("N2")} GiB")
                         .ToList();

                cmbSourcePhysical.DataSource = ds;
            }
        }
示例#10
0
 public static void RefreshMemory()
 {
     if (DateTime.UtcNow - _lastMemoryRead > MinimumRefreshInterval)
     {
         var osQuery    = new WqlObjectQuery("SELECT * FROM Win32_OperatingSystem");
         var osSearcher = new ManagementObjectSearcher(osQuery);
         foreach (var os in osSearcher.Get())
         {
             PhysicalMemoryTotal = Convert.ToUInt64(os["TotalVisibleMemorySize"]) * 1024;
             PhysicalMemoryFree  = Convert.ToUInt64(os["FreePhysicalMemory"]) * 1024;
             VirtualMemoryTotal  = Convert.ToUInt64(os["TotalVirtualMemorySize"]) * 1024;
             VirtualMemoryFree   = Convert.ToUInt64(os["FreeVirtualMemory"]) * 1024;
         }
         _lastMemoryRead = DateTime.UtcNow;
     }
 }
示例#11
0
        public static string GetExecutableOfService(string serviceName)
        {
            var wqlObjectQuery = new WqlObjectQuery(string.Format("SELECT * FROM Win32_Service WHERE Name = '{0}'", serviceName));

            using (var managementObjectSearcher = new ManagementObjectSearcher(wqlObjectQuery))
            {
                var managementObjectCollection = managementObjectSearcher.Get();

                return((
                           from ManagementObject managementObject in managementObjectCollection
                           select managementObject.GetPropertyValue("PathName").ToString()
                           into executableOfService
                           select ParseExePath(executableOfService)
                           ).FirstOrDefault());
            }
        }
示例#12
0
        private void butProc_Click(object sender, EventArgs e)
        {
            // Соединяемся с удаленной машиной
            //ConnectionOptions options = new ConnectionOptions();
            //options.Username = @"gamma\admin";
            //options.Password = "******";

            ManagementScope scope =
                new ManagementScope(
                    "\\\\localhost\\root\\cimv2");

            scope.Connect();

            // Делаем запрос к удаленной машине
            WqlObjectQuery query = new WqlObjectQuery("Select * from Win32_Processor");

            ManagementObjectSearcher find = new ManagementObjectSearcher(query);
            string nl = Environment.NewLine;
            int    i  = 0;

            foreach (ManagementObject mo in find.Get())
            {
                textBox1.Text += ("-------------- Processor #" + i + " --------------") + nl;
                textBox1.Text += ("Processor address width in bits.............." + mo["AddressWidth"]) + nl;
                textBox1.Text += ("Caption......................................" + mo["Caption"]) + nl;
                textBox1.Text += ("Processor address width in bits.............." + mo["AddressWidth"]) + nl;
                textBox1.Text += ("Current clock speed (in MHz)................." + mo["CurrentClockSpeed"]) + nl;
                textBox1.Text += ("Processor data width........................." + mo["DataWidth"]) + nl;
                textBox1.Text += ("Unique string identification................." + mo["DeviceID"]) + nl;
                textBox1.Text += ("External clock frequency....................." + mo["ExtClock"]) + nl;
                textBox1.Text += ("Processor data width........................." + mo["DataWidth"]) + nl;
                textBox1.Text += ("L2 cache size................................" + mo["L2CacheSize"]) + nl;
                textBox1.Text += ("L2 cache speed..............................." + mo["L2CacheSpeed"]) + nl;
                textBox1.Text += ("Load percentage (average value for second)..." + mo["LoadPercentage"]) + nl;
                textBox1.Text += ("Manufacturer................................." + mo["Manufacturer"]) + nl;
                textBox1.Text += ("Maximum speed (in MHz)......................." + mo["MaxClockSpeed"]) + nl;
                textBox1.Text += ("Name........................................." + mo["Name"]) + nl;
                textBox1.Text += ("Support for power management................." + mo["PowerManagementSupported"]) + nl;
                textBox1.Text += ("Unique identificator describing processor...." + mo["ProcessorId"]) + nl;
                textBox1.Text += ("Role (CPU/math).............................." + mo["Role"]) + nl;
                textBox1.Text += ("Socket designation..........................." + mo["SocketDesignation"]) + nl;
                textBox1.Text += ("Status......................................." + mo["Status"]) + nl;
                textBox1.Text += ("Processor version............................" + mo["Version"]) + nl;
                textBox1.Text += ("Socket voltage..............................." + mo["VoltageCaps"]) + nl;
                i++;
            }
        }
示例#13
0
        }//end of getsn

        public static string GetOS(string computer)
        {
            ManagementScope scope = new ManagementScope("\\\\" + computer + "\\root\\cimv2");

            scope.Connect();
            WqlObjectQuery wqlQuery =
                new WqlObjectQuery("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(scope, wqlQuery);
            string os = "";

            foreach (ManagementObject n in searcher.Get())
            {
                os = n["Caption"].ToString();
            }
            return(os);
        }//end of getos
示例#14
0
        }//end of getsn

        public static string GetSize(string computer)
        {
            ManagementScope scope = new ManagementScope("\\\\" + computer + "\\root\\cimv2");

            scope.Connect();
            WqlObjectQuery wqlQuery =
                new WqlObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3");
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(scope, wqlQuery);
            string size = "";

            foreach (ManagementObject n in searcher.Get())
            {
                size = n["Size"].ToString();
            }
            return(size);
        }//end of getsize
示例#15
0
        }//end of gets

        public static string GetCores(string computer)
        {
            ManagementScope scope = new ManagementScope("\\\\" + computer + "\\root\\cimv2");

            scope.Connect();
            WqlObjectQuery wqlQuery =
                new WqlObjectQuery("SELECT * FROM Win32_Processor");
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(scope, wqlQuery);
            string cores = "";

            foreach (ManagementObject n in searcher.Get())
            {
                cores = n["NumberOfCores"].ToString();
            }
            return(cores);
        }//end of gets
示例#16
0
        }//end of gets

        public static string GetProcessMan(string computer)
        {
            ManagementScope scope = new ManagementScope("\\\\" + computer + "\\root\\cimv2");

            scope.Connect();
            WqlObjectQuery wqlQuery =
                new WqlObjectQuery("SELECT * FROM Win32_Processor");
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(scope, wqlQuery);
            string manuf = "";

            foreach (ManagementObject n in searcher.Get())
            {
                manuf = n["Manufacturer"].ToString();
            }
            return(manuf);
        }//end of gets
示例#17
0
        public static IEnumerable <ServiceDetails> GetServicesInstalledInDirectory(string directory)
        {
            var wqlObjectQuery             = new WqlObjectQuery("SELECT * FROM Win32_Service");
            var managementObjectSearcher   = new ManagementObjectSearcher(wqlObjectQuery);
            var managementObjectCollection = managementObjectSearcher.Get();

            return(managementObjectCollection
                   .OfType <ManagementObject>()
                   .Where(svc => svc.GetPropertyValue("PathName") != null)
                   .Where(svc => svc.GetPropertyValue("PathName").ToString().Contains(directory))
                   .Select(svc => new ServiceDetails
            {
                PathName = svc.GetPropertyValue("PathName").ToString(),
                DisplayName = svc.GetPropertyValue("DisplayName").ToString(),
                ServiceName = svc.GetPropertyValue("Name").ToString()
            }));
        }
示例#18
0
        public List <string> MakeQuery(string wqlQuery)
        {
            WqlObjectQuery           woq = new WqlObjectQuery(wqlQuery);
            ManagementObjectSearcher mos = new ManagementObjectSearcher(woq);

            List <string> results = new List <string>();

            foreach (ManagementObject result in mos.Get())
            {
                foreach (PropertyData property in result.Properties)
                {
                    results.Add(property.Value.ToString());
                }
            }

            return(results);
        }
示例#19
0
        public static string GetModel(string computer)
        {
            ManagementScope scope = new ManagementScope("\\\\" + computer + "\\root\\cimv2");

            scope.Connect();
            WqlObjectQuery wqlQuery =
                new WqlObjectQuery("SELECT * FROM Win32_ComputerSystemProduct");
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(scope, wqlQuery);
            string model = "";

            foreach (ManagementObject n in searcher.Get())
            {
                model = n["Version"].ToString();
            }
            return(model);
        }//end of getmodel
示例#20
0
        private static OsInfo GetOSInformation()
        {
            OsInfo                   inf      = new OsInfo();
            WqlObjectQuery           objQuery = new WqlObjectQuery("select * from win32_OperatingSystem");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(objQuery);

            object val;

            foreach (ManagementObject share in searcher.Get())
            {
                val = share["Name"];
                if (null != val)
                {
                    inf.OS = val.ToString().Split('|')[0];
                }
                else
                {
                    inf.OS = string.Empty;
                }

                val = share["Locale"];
                if (null != val)
                {
                    switch (val.ToString())
                    {
                    case "0409":
                        inf.OSLocale = "ENG";
                        break;

                    case "0411":
                        inf.OSLocale = "JPN";
                        break;

                    case "0407":
                        inf.OSLocale = "GER";
                        break;
                    }
                }
                else
                {
                    inf.OSLocale = string.Empty;
                }
            }

            return(inf);
        }
        public List <string> GetSysDevList()
        {
            WqlObjectQuery query = new WqlObjectQuery("SELECT * FROM CIM_LogicalDevice");

            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
            {
                List <string> devList = new List <string>();
                ManagementObjectCollection collection;
                collection = searcher.Get();
                foreach (ManagementBaseObject mbo in collection)
                {
                    devList.Add(mbo["DeviceID"].ToString());
                }
                collection.Dispose();
                return(devList);
            }
        }
示例#22
0
        }//end of getmodel

        public static string GetSN(string computer)
        {
            ManagementScope scope = new ManagementScope("\\\\" + computer + "\\root\\cimv2");

            scope.Connect();
            WqlObjectQuery wqlQuery =
                new WqlObjectQuery("SELECT * FROM Win32_BIOS");
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(scope, wqlQuery);
            string sn = "";

            foreach (ManagementObject n in searcher.Get())
            {
                sn = n["SerialNumber"].ToString();
            }
            return(sn);
        }//end of getsn
示例#23
0
        }//end of gets

        public static string GetMaxSpeed(string computer)
        {
            ManagementScope scope = new ManagementScope("\\\\" + computer + "\\root\\cimv2");

            scope.Connect();
            WqlObjectQuery wqlQuery =
                new WqlObjectQuery("SELECT * FROM Win32_Processor");
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(scope, wqlQuery);
            string speed = "";

            foreach (ManagementObject n in searcher.Get())
            {
                speed = n["MaxClockSpeed"].ToString();
            }
            return(speed);
        }//end of gets
示例#24
0
        }//end of getos

        public static string GetServicePack(string computer)
        {
            ManagementScope scope = new ManagementScope("\\\\" + computer + "\\root\\cimv2");

            scope.Connect();
            WqlObjectQuery wqlQuery =
                new WqlObjectQuery("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(scope, wqlQuery);
            string service = "";

            foreach (ManagementObject n in searcher.Get())
            {
                service = n["servicepackmajorversion"].ToString();
            }
            return(service);
        }//end of getsn
示例#25
0
        }//end of getsn

        public static string GetLastBootUp(string computer)
        {
            ManagementScope scope = new ManagementScope("\\\\" + computer + "\\root\\cimv2");

            scope.Connect();
            WqlObjectQuery wqlQuery =
                new WqlObjectQuery("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(scope, wqlQuery);
            string boottime = "";

            foreach (ManagementObject n in searcher.Get())
            {
                boottime = n["LastBootUpTime"].ToString();
            }
            return(boottime);
        }//end of getsn
        private int checkAlreadyRunning()
        {
            string procName = "";

            this.Dispatcher.Invoke(() =>
            {
                procName = tbProcessName.Text;
            });

            WqlObjectQuery qry = new WqlObjectQuery("SELECT Name FROM Win32_Process WHERE Name=\"" + procName + "\"");

            searcher = new ManagementObjectSearcher(qry);

            ManagementObjectCollection res = searcher.Get();

            return(res.Count);
        }
示例#27
0
        //获得磁盘剩余空间大小  'D:' || "D:"
        public static UInt64 GetDiskFreeSpaceSize(string disk)
        {
            WqlObjectQuery           woq = new WqlObjectQuery("SELECT * FROM Win32_LogicalDisk WHERE DeviceID = " + disk + "");
            ManagementObjectSearcher mos = new ManagementObjectSearcher(woq);
            UInt64 a = 0;
            UInt64 b = 1024;

            foreach (ManagementObject mo in mos.Get())
            {
                //Console.WriteLine("Description: " + mo["Description"]);
                //Console.WriteLine("File system: " + mo["FileSystem"]);
                //Console.WriteLine("Free disk space: " + mo["FreeSpace"]);
                //Console.WriteLine("Size: " + mo["Size"]);
                a += (Convert.ToUInt64(mo["FreeSpace"]) / b) / b;
            }
            return(a);
        }
        public static string GetWindowsServicePath(string serviceName)
        {
            WqlObjectQuery             wqlObjectQuery             = new WqlObjectQuery(string.Format("SELECT * FROM Win32_Service WHERE Name = '{0}'", serviceName));
            ManagementObjectSearcher   managementObjectSearcher   = new ManagementObjectSearcher(wqlObjectQuery);
            ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get();

            foreach (ManagementObject managementObject in managementObjectCollection)
            {
                var path = managementObject.GetPropertyValue("PathName").ToString();

                var serviceExe = GetServiceExecutable(path);
                var fileInfo   = new FileInfo(serviceExe);
                return(fileInfo.Directory.FullName);
            }

            return(null);
        }
示例#29
0
        private void btnCheck_Click(object sender, EventArgs e)
        {
            WqlObjectQuery           q   = new WqlObjectQuery("SELECT * FROM Win32_IDEController");
            ManagementObjectSearcher res = new ManagementObjectSearcher(q);

            lblHDDChanels.Text = string.Empty;
            foreach (ManagementObject o in res.Get())
            {
                string Caption = o["Caption"].ToString();

                lblHDDChanels.Text += Caption + "\n\n";
                if (Caption.Contains("Serial"))
                {
                    lblInterface.Text = "S-ATA";
                }
            }
        }
示例#30
0
        /// <summary>
        /// invokes a method for all class instances
        /// </summary>
        /// <param name="className">Must be a name of a WMI dynamic class from the NV namespace</param>
        /// <param name="methodName">Name of a WMI method</param>
        public void InvokeMethod(string className, string methodName)
        {
            try
            {
                ManagementObjectSearcher searcher      = null;
                ManagementClass          classInstance = null;

                // Performs WMI object query in selected namespace
                string          wmiScope = target + nvWmiNamespace;
                ManagementScope scope    = new ManagementScope(wmiScope);
                WqlObjectQuery  query    = new WqlObjectQuery("select * from " + className);
                scope.Connect();

                searcher      = new ManagementObjectSearcher(scope, query, null);
                classInstance = new ManagementClass(target + nvWmiNamespace, className, null);

                ManagementBaseObject inParams = classInstance.GetMethodParameters(methodName);

                // invoke method for each instance, selected by WQL query
                // assumption is that specified method doesn't require any parameters (e.g. "info" method)
                int i = 0;
                foreach (ManagementObject obj in searcher.Get())
                {
                    ManagementBaseObject outParams = null;
                    outParams = obj.InvokeMethod(methodName, inParams, null);
                    string rc = outParams["ReturnValue"].ToString();
                    Console.WriteLine("return of the WMI {0}.{1} method call:", className, methodName);
                    Console.WriteLine(rc);
                    Console.WriteLine("================================");

                    // printing out some properties of the current Gpu instance
                    obj.Get(); // bind WMI object to an instance of the .NET ManagementObject
                    Console.WriteLine("Unique name of this object: {0}", obj["uname"]);
                    Console.WriteLine("Unique ID of this object: {0}", obj["id"].ToString());
                    ++i;
                }
                Console.WriteLine("================================");
            }
            catch (ManagementException e)
            {
                Console.WriteLine(MethodBase.GetCurrentMethod().Name + " - Exception caught: " + e.Message);
                Console.WriteLine("Stack trace: " + e.StackTrace);
            }
        }
示例#31
0
文件: MainForm.cs 项目: renyh1013/dp2
        // 速度慢
        public static string GetPathOfService(string serviceName)
        {
            WqlObjectQuery wqlObjectQuery = new WqlObjectQuery(string.Format("SELECT * FROM Win32_Service WHERE Name = '{0}'", serviceName));
            ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(wqlObjectQuery);
            ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get();

            foreach (ManagementObject managementObject in managementObjectCollection)
            {
                return managementObject.GetPropertyValue("PathName").ToString();
            }

            return null;
        }