Example #1
0
            void DisplayPartions(HANDLE hStore)
            {
                HANDLE   hSearch    = INVALID_HANDLE_VALUE;
                HANDLE   hPartition = INVALID_HANDLE_VALUE;
                PARTINFO partInfo   = new PARTINFO();

                partInfo.cbSize = (uint)Marshal.SizeOf(typeof(PARTINFO));

                hSearch = StorageManager.FindFirstPartition(hStore, ref partInfo);

                if (INVALID_HANDLE_VALUE != hSearch)
                {
                    do
                    {
                        if ((PARTITION_ATTRIBUTE_MOUNTED & partInfo.dwAttributes) != 0)
                        {
                            Console.WriteLine(string.Format("\t\tPartition Mounted"));
                        }
                        else
                        {
                            Console.WriteLine(string.Format("\t\tPartition NOT Mounted"));
                        }

                        Console.WriteLine(string.Format("\t\tPartition Name {0}\n", partInfo.szPartitionName));
                        //Console.WriteLine(string.Format("\t\tSize  {0}\n", partInfo.cbSize));
                        Console.WriteLine(string.Format("\t\tFile System {0}\n", partInfo.szFileSys));
                        Console.WriteLine(string.Format("\t\tVolume Name {0}\n", partInfo.szVolumeName));
                        Console.WriteLine(string.Format("\t\tNumber of Sectors {0}\n", partInfo.snNumSectors));
                        Console.WriteLine(string.Format("\t\tAttributes"));
                        if ((partInfo.dwAttributes & PARTITION_ATTRIBUTE_EXPENDABLE) != 0)
                        {
                            Console.WriteLine(" PARTITION_ATTRIBUTE_EXPENDABLE");
                        }
                        if ((partInfo.dwAttributes & PARTITION_ATTRIBUTE_READONLY) != 0)
                        {
                            Console.WriteLine(" PARTITION_ATTRIBUTE_READONLY");
                        }
                        if ((partInfo.dwAttributes & PARTITION_ATTRIBUTE_BOOT) != 0)
                        {
                            Console.WriteLine(" PARTITION_ATTRIBUTE_BOOT");
                        }
                        if ((partInfo.dwAttributes & PARTITION_ATTRIBUTE_AUTOFORMAT) != 0)
                        {
                            Console.WriteLine(" PARTITION_ATTRIBUTE_AUTOFORMAT");
                        }
                        if ((partInfo.dwAttributes & PARTITION_ATTRIBUTE_MOUNTED) != 0)
                        {
                            Console.WriteLine(" PARTITION_ATTRIBUTE_MOUNTED");
                        }
                        if ((partInfo.dwAttributes & 0) != 0)
                        {
                            Console.WriteLine(" None");
                        }
                        Console.WriteLine("\n");


                        // Convert the partion type value to a string
                        var bpartType = string.Format("{0:X2}", partInfo.bPartType);
                        Console.WriteLine("Partition type code " + bpartType);

                        using (var registryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System\\StorageManager\\PartitionTable"))
                        {
                            Console.WriteLine("Partition Type value " + registryKey.GetValue(bpartType));
                        }
                    }while (StorageManager.FindNextPartition(hSearch, ref partInfo));
                    StorageManager.FindClosePartition(hSearch);
                }
            }
Example #2
0
            public void DisplayDisks()
            {
                STOREINFO si      = new STOREINFO();
                HANDLE    hSearch = INVALID_HANDLE_VALUE;

                si.cbSize = (uint)Marshal.SizeOf(typeof(STOREINFO));

                // enumerate first store
                hSearch = StorageManager.FindFirstStore(ref si);

                if (INVALID_HANDLE_VALUE != hSearch)
                {
                    do
                    {
                        Console.WriteLine("Device Name " + si.szDeviceName);
                        Console.WriteLine("Name " + si.szStoreName);
                        var storageClass = "STORAGE_DEVICE_CLASS_MULTIMEDIA";

                        if (si.dwDeviceClass == STORAGE_DEVICE_CLASS_BLOCK)
                        {
                            storageClass = "STORAGE_DEVICE_CLASS_BLOCK";
                        }

                        Console.WriteLine("Class " + storageClass);
                        Console.WriteLine("Type ");

                        switch (si.dwDeviceType)
                        {
                        case STORAGE_DEVICE_TYPE_PCIIDE:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_PCIIDE\n");
                            break;

                        case STORAGE_DEVICE_TYPE_FLASH:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_FLASH\n");
                            break;

                        case STORAGE_DEVICE_TYPE_ATA:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_ATA\n");
                            break;

                        case STORAGE_DEVICE_TYPE_ATAPI:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_ATAPI\n");
                            break;

                        case STORAGE_DEVICE_TYPE_SRAM:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_SRAM\n");
                            break;

                        case STORAGE_DEVICE_TYPE_DVD:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_DVD\n");
                            break;

                        case STORAGE_DEVICE_TYPE_CDROM:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_CDROM\n");
                            break;

                        case STORAGE_DEVICE_TYPE_USB:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_USB\n");
                            break;

                        case STORAGE_DEVICE_TYPE_1394:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_1394\n");
                            break;

                        case STORAGE_DEVICE_TYPE_DOC:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_DOC\n");
                            break;

                        case STORAGE_DEVICE_TYPE_UNKNOWN:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_UNKNOWN\n");
                            break;

                        case STORAGE_DEVICE_TYPE_REMOVABLE_DRIVE:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_REMOVABLE_DRIVE\n");
                            break;

                        case STORAGE_DEVICE_TYPE_REMOVABLE_MEDIA:
                            Console.WriteLine("STORAGE_DEVICE_TYPE_REMOVABLE_MEDIA\n");
                            break;

                        default:
                            Console.WriteLine("Unkown device type " + si.dwDeviceType);
                            break;
                        }

                        Console.WriteLine("Flags");
                        if ((si.dwDeviceFlags & STORAGE_DEVICE_FLAG_READWRITE) != 0)
                        {
                            Console.WriteLine("STORAGE_DEVICE_FLAG_READWRITE");
                        }
                        if ((si.dwDeviceFlags & STORAGE_DEVICE_FLAG_READONLY) != 0)
                        {
                            Console.WriteLine("STORAGE_DEVICE_FLAG_READONLY");
                        }
                        if ((si.dwDeviceFlags & STORAGE_DEVICE_FLAG_TRANSACTED) != 0)
                        {
                            Console.WriteLine(" STORAGE_DEVICE_FLAG_TRANSACTED");
                        }
                        if ((si.dwDeviceFlags & STORAGE_DEVICE_FLAG_MEDIASENSE) != 0)
                        {
                            Console.WriteLine("STORAGE_DEVICE_FLAG_MEDIASENSE");
                        }
                        if (si.dwDeviceFlags == 0)
                        {
                            Console.WriteLine(" None");
                        }


                        Console.WriteLine("Bytes per Sector " + si.dwBytesPerSector);
                        Console.WriteLine("Attributes");
                        if ((si.dwAttributes & STORE_ATTRIBUTE_READONLY) != 0)
                        {
                            Console.WriteLine(" STORE_ATTRIBUTE_READONLY");
                        }
                        if ((si.dwAttributes & STORE_ATTRIBUTE_REMOVABLE) != 0)
                        {
                            Console.WriteLine(" STORE_ATTRIBUTE_REMOVABLE");
                        }
                        if ((si.dwAttributes & STORE_ATTRIBUTE_UNFORMATTED) != 0)
                        {
                            Console.WriteLine(" STORE_ATTRIBUTE_UNFORMATTED");
                        }
                        if ((si.dwAttributes & STORE_ATTRIBUTE_AUTOFORMAT) != 0)
                        {
                            Console.WriteLine("STORE_ATTRIBUTE_AUTOFORMAT");
                        }
                        if ((si.dwAttributes & STORE_ATTRIBUTE_AUTOPART) != 0)
                        {
                            Console.WriteLine("STORE_ATTRIBUTE_AUTOPART");
                        }
                        if ((si.dwAttributes & STORE_ATTRIBUTE_AUTOMOUNT) != 0)
                        {
                            Console.WriteLine("STORE_ATTRIBUTE_AUTOMOUNT");
                        }
                        if (si.dwAttributes == 0)
                        {
                            Console.WriteLine("None");
                        }


                        Console.WriteLine("Partition Count " + si.dwPartitionCount);
                        Console.WriteLine("Mount Count " + si.dwMountCount);


                        HANDLE hStore = StorageManager.OpenStore(si.szDeviceName);

                        if (hStore != INVALID_HANDLE_VALUE)
                        {
                            DisplayPartions(hStore);
                        }
                        else
                        {
                            Console.WriteLine("OpenSelectedStore failed");
                        }
                    }while (StorageManager.FindNextStore(hSearch, ref si));
                    StorageManager.FindCloseStore(hSearch);
                }
            }