Ejemplo n.º 1
0
        public static void OSInfo()
        {
            using (WMI wmi = new WMI("."))
            {
                if (!wmi.Connect())
                {
                    Console.WriteLine("Unable to Connect");
                    return;
                }

                wmi.ExecuteQuery("Select * FROM Win32_OperatingSystem");
                ManagementObjectCollection results = wmi.GetResults();
                if (null == results)
                {
                    Console.WriteLine("WMI Query Failed");
                    return;
                }
                ManagementObject result = results.OfType <ManagementObject>().FirstOrDefault();
                Console.WriteLine("OS Information");
                Console.WriteLine("--------------");
                Console.WriteLine("{0} {1} ({2})", result["Caption"], result["OSArchitecture"], result["BuildNumber"]);
                Console.WriteLine("Computer Name    : {0}", result["CSName"]);
                Console.WriteLine("Free Memory      : {0}/{1}", result["FreeVirtualMemory"], result["TotalVirtualMemorySize"]);
                Console.WriteLine("Country & Locale : {0} - {1}", result["CountryCode"], result["Locale"]);
                Console.WriteLine("System Device    : {0}", result["SystemDevice"]);
                Console.WriteLine("BitLocker Level  : {0}", result["EncryptionLevel"]);
                Console.WriteLine("InstallDate      : {0}", result["InstallDate"]);
                Console.WriteLine("LastBootUpTime   : {0}", result["LastBootUpTime"]);
                Console.WriteLine("LocalDateTime    : {0}", result["LocalDateTime"]);
            }
        }
Ejemplo n.º 2
0
 public static void WMIQuery(String system, String username, String password, String query)
 {
     using (WMI wmi = new WMI(system))
     {
         wmi.Connect(username, password);
         wmi.ExecuteQuery(query);
     }
 }
Ejemplo n.º 3
0
        public static void AntivirusProduct()
        {
            using (WMI wmi = new WMI(".", @"root\SecurityCenter2"))
            {
                if (!wmi.Connect())
                {
                    Console.WriteLine("Unable to Connect");
                    return;
                }

                wmi.ExecuteQuery("Select * FROM AntivirusProduct");
                wmi.GetResults();
            }
        }
Ejemplo n.º 4
0
        public static void MappedDrives()
        {
            using (WMI wmi = new WMI("."))
            {
                if (!wmi.Connect())
                {
                    Console.WriteLine("Unable to Connect");
                    return;
                }

                wmi.ExecuteQuery("Select * FROM Win32_MappedLogicalDisk");
                ManagementObjectCollection results = wmi.GetResults();
                if (null == results)
                {
                    Console.WriteLine("WMI Query Failed");
                    return;
                }
                try
                {
                    Console.WriteLine("{0,-9}  {1,-4}  {2,-15}  {3,-10} {4}", "Device ID", "Name", "VolumeName", "FileSystem", "FreeSpace");
                    Console.WriteLine("{0,-9}  {1,-4}  {2,-15}  {3,-10} {4}", "---------", "----", "----------", "----------", "---------");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                foreach (ManagementObject result in results)
                {
                    try
                    {
                        Console.WriteLine("{0,-9}  {1,-4}  {2,-15}  {3,-10} {4}/{5} M     {6}",
                                          result["DeviceID"],
                                          result["Name"],
                                          result["VolumeName"],
                                          result["FileSystem"],
                                          (UInt64)result["FreeSpace"] / 1048576,
                                          (UInt64)result["Size"] / 1048576,
                                          result["ProviderName"]);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }