Exemplo n.º 1
0
 public string OperatingSystemLicensingInfo()
 {
     try
     {
         return(Win32KernelCalls.GetWindowsCdKey());
     }
     catch (Exception e)
     {
         Console.WriteLine("-> Failed reading the Windows License Key, sorry. ({0})", e.GetType().Name);
         return("");
     }
 }
Exemplo n.º 2
0
        public List <SoftwareInfo> GetSoftware()
        {
            Console.Write("Enumerating software");
            int swEnum = 0;

            if (Win32KernelCalls.IsOS64Bit())
            {
                //64-bit OS
                List <SoftwareInfo> result = new List <SoftwareInfo>();
                try
                {
                    ManagementObjectSearcher searcher =
                        new ManagementObjectSearcher("root\\CIMV2",
                                                     "SELECT * FROM Win32_Product");

                    foreach (ManagementObject queryObj in searcher.Get())
                    {
                        SoftwareInfo child = new SoftwareInfo();
                        child.productName     = (string)queryObj["Caption"];
                        child.installPath     = (string)queryObj["InstallLocation"];
                        child.manufacterer    = (string)queryObj["Vendor"];
                        child.registrationKey = "";
                        child.version         = (string)queryObj["Version"];
                        result.Add(child);
                        if ((swEnum++ % 10) == 0)
                        {
                            Console.Write(".");
                        }
                    }
                }
                catch (Exception e)
                {
                    throw;
                }

                //Der folgende Code listet alle 32-bit Applikation. (Das ist schon einfacher... :D)
                RegistryKey targetKey =
                    Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
                ScanSoftwareRegistryKey(targetKey, result);
                result.Sort((x, y) => (x.CompareTo(y)));
                Console.WriteLine(".");
                return(result);
            }
            else
            {
                //32-bit OS (trivial...)
                RegistryKey targetKey =
                    Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
                Console.WriteLine(".");
                return(ScanSoftwareRegistryKey(targetKey));
            }
        }
Exemplo n.º 3
0
        public string GetVolumeSerialNumber(string volume)
        {
            StringBuilder volumeNameBuffStringBuilder = new StringBuilder();
            uint          volumeSerialNumber, MaximumComponentLength;

            Win32KernelCalls.FileSystemFeature flags;
            StringBuilder filesystemNameBuffStringBuilder = new StringBuilder();

            try
            {
                Win32KernelCalls.GetVolumeInformation(volume, volumeNameBuffStringBuilder, Byte.MaxValue,
                                                      out volumeSerialNumber, out MaximumComponentLength, out flags, filesystemNameBuffStringBuilder,
                                                      Byte.MaxValue);

                return(String.Format("{0:X}", volumeSerialNumber));
            }
            catch (Exception)
            {
                return(String.Empty);
            }
        }
Exemplo n.º 4
0
        public List <StorageDevice> GetStorageDevices()
        {
            List <StorageDevice> result = new List <StorageDevice>();

            //C/DVD Laufwerke finden.
            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_CDROMDrive");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    StorageDevice child    = new StorageDevice();
                    string        deviceId = (string)queryObj["DeviceID"];
                    if (!string.IsNullOrEmpty(deviceId))
                    {
                        child.connected = (deviceId).StartsWith("SCSI")
                            ? StorageDevice.ConnectionType.Extern
                            : StorageDevice.ConnectionType.Intern;
                    }
                    else
                    {
                        child.connected = StorageDevice.ConnectionType.Other;
                    }
                    child.description = (string)queryObj["Description"];
                    if (!Win32KernelCalls.IsWindowsXP())
                    {
                        child.serial = string.Format("{0}", queryObj["SerialNumber"]);                                  //Seriennummern für DVD Laufwerke waren bei XP offenbar noch nicht erfunden...
                    }
                    child.title = (string)queryObj["Name"];
                    child.type  = StorageDevice.StorageDeviceType.CDVD;
                    child.unit  = StorageDevice.C__CATG__MEMORY_UNIT.C__MEMORY_UNIT__MB;
                    if (child.title.Contains("CLONEDRIVE"))
                    {
                        continue;                                     //Virtual CloneDrive juckt uns nicht...
                    }
                    result.Add(child);
                }
            }
            catch (Exception)
            {
                throw;
            }

            //Festplatten finden
            try
            {
                hardDisks = new List <StorageDevice>();
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_DiskDrive");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    StorageDevice child    = new StorageDevice();
                    string        deviceId = (string)queryObj["DeviceID"];
                    if (!string.IsNullOrEmpty(deviceId))
                    {
                        child.connected = (deviceId).StartsWith("USB")
                            ? StorageDevice.ConnectionType.Extern
                            : StorageDevice.ConnectionType.Intern;
                    }
                    else
                    {
                        child.connected = StorageDevice.ConnectionType.Other;
                    }
                    child.description = (string)queryObj["Description"];
                    if (!Win32KernelCalls.IsWindowsXP())
                    {
                        child.serial = string.Format("{0}", queryObj["SerialNumber"]);                                  //siehe oben
                    }
                    child.title    = (string)queryObj["Caption"];
                    child.unit     = StorageDevice.C__CATG__MEMORY_UNIT.C__MEMORY_UNIT__GB;
                    child.capacity = (double)((long)(Convert.ToInt64(queryObj["Size"]) / 1000 / 1000 / 1000));
                    //Ja, 1000, nicht 1024,
                    //zwischen Mebibyte und Megabyte ist ein Unterschied! ;)
                    //Oder habt ihr schon mal SSDs mit 111GB beworben gesehen?

                    string mediaType = (string)queryObj["MediaType"];
                    if (!string.IsNullOrEmpty(mediaType))
                    {
                        if (queryObj["MediaType"].ToString().Contains("Removable"))
                        //Gut, dass WMI Sprach-unabhängig immer Werte auf englisch angibt.
                        {
                            child.type = StorageDevice.StorageDeviceType.UsbStick;
                        }
                        else
                        {
                            child.type = StorageDevice.StorageDeviceType.HardDisk;
                        }
                    }
                    else
                    {
                        child.type = StorageDevice.StorageDeviceType.HardDisk;  //Unter Windows 10 lässt sich dies nicht mehr zuverlässig ermitteln, in dubio pro Festplatte.
                    }
                    result.Add(child);
                    hardDisks.Add(child);
                }
            }
            catch (Exception)
            {
                throw;
            }

            //Diskettenlaufwerke finden
            if (!Win32KernelCalls.IsWindows10())                //Windows 10 kann man nicht mehr nach Diskettenlaufwerken fragen...
            {
                try {
                    ManagementObjectSearcher searcher =
                        new ManagementObjectSearcher("root\\CIMV2",
                                                     "SELECT * FROM Win32_FloppyDrive");

                    foreach (ManagementObject queryObj in searcher.Get())
                    {
                        StorageDevice child    = new StorageDevice();
                        string        deviceId = (string)queryObj ["DeviceID"];
                        if (!string.IsNullOrEmpty(deviceId))
                        {
                            child.connected = (deviceId).StartsWith("USB")
                            ? StorageDevice.ConnectionType.Extern
                            : StorageDevice.ConnectionType.Intern;
                        }
                        else
                        {
                            child.connected = StorageDevice.ConnectionType.Other;
                        }
                        child.description = (string)queryObj ["Description"];
                        child.title       = (string)queryObj ["Name"];
                        child.unit        = StorageDevice.C__CATG__MEMORY_UNIT.C__MEMORY_UNIT__KB;
                        child.type        = StorageDevice.StorageDeviceType.Floppy;
                        result.Add(child);
                    }
                } catch (Exception) {
                    throw;
                }
            }

            //Bandlaufwerke finden
            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_TapeDrive");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    StorageDevice child = new StorageDevice();
                    child.connected = StorageDevice.ConnectionType.Other;
                    //Bei Tapes lässt sich nicht zuverlässig bestimmen, ob sie intern oder extern sind - da es wohl so oder so SCSI ist...
                    child.description = (string)queryObj["Description"];
                    //Zeigt zumindest an, ob es sich um LTO, DDS, oder Whatever-Tapes handelt.
                    child.title = (string)queryObj["Name"];
                    child.type  = StorageDevice.StorageDeviceType.Tape;
                    child.unit  = StorageDevice.C__CATG__MEMORY_UNIT.C__MEMORY_UNIT__GB;
                    //Hat heutzutage noch irgendwer was kleineres an Tapes? :o
                    result.Add(child);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }
Exemplo n.º 5
0
 public bool IsServer()
 {
     return(Win32KernelCalls.IsOS(Win32KernelCalls.OS_ANYSERVER));
 }
Exemplo n.º 6
0
 public string uname()
 {
     return(Win32KernelCalls.WindowsProductName());
 }