Esempio n. 1
0
 public static extern HANDLE FindFirstPartition(HANDLE hStore, ref PARTINFO pPartInfo);
Esempio n. 2
0
 public static extern bool FindNextPartition(HANDLE hStore, ref PARTINFO pPartInfo);
Esempio n. 3
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);
                }
            }