sto facendo qualche esperimento, nulla di cheOriginariamente inviato da kentaromiura
MA esattamente tu cosa vuoi fare? non ho ben capito..![]()
qua c'è la nuova Main ma il .NET va in palla e si auto termina per via di qualche errore nella chiamata a ReadFilecodice:static void Main(string[] args) { // Apre il disco IntPtr diskHandle = CreateFile( @"\\.\PhysicalDrive0", EFileAccess.GenericRead | EFileAccess.GenericWrite, EFileShare.Read | EFileShare.Write, IntPtr.Zero, ECreationDisposition.OpenExisting, EFileAttributes.Device | EFileAttributes.NoBuffering | EFileAttributes.Write_Through, IntPtr.Zero); if (diskHandle.ToInt32() == -1) { Console.WriteLine("Impossibile accedere al disco"); Console.WriteLine("Errore: " + Marshal.GetLastWin32Error().ToString()); Console.ReadLine(); Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); return; } //Legge il primo settore del disco try { byte[] buffer = new byte[512]; uint readedBytes = 0; System.Threading.NativeOverlapped fakeOverlapped = new System.Threading.NativeOverlapped(); if (ReadFile(diskHandle, out buffer, 512, out readedBytes, ref fakeOverlapped) == false) { Console.WriteLine("Impossibile leggere il primo settore del disco"); Console.WriteLine("Errore: " + Marshal.GetLastWin32Error().ToString()); Console.ReadLine(); CloseHandle(diskHandle); Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); return; } Console.WriteLine(readedBytes.ToString()); } catch { Console.WriteLine("Impossibile leggere il primo settore del disco"); Console.WriteLine("Errore: " + Marshal.GetLastWin32Error().ToString()); Console.ReadLine(); CloseHandle(diskHandle); Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); return; } Console.ReadLine(); // Legge le varie entries nell'mbr appena letto for (int i = 0; i < 4; i++) { Console.WriteLine("Partition {0}:", i); /* byte[] buffer = new byte[16]; if (ReadFile(diskHandle,out buffer, (uint)buffer.Length, out readedBytes, ref fakeOverlapped) == false) { // Verifica se la partizione è avviabile if (buffer[0] == 0) { Console.WriteLine("\tAvviabile: SI"); } else { Console.WriteLine("\tAvviabile: NO"); } } else { Console.WriteLine("Impossibile leggere i dati della partizione!"); Console.WriteLine("Errore: " + Marshal.GetLastWin32Error().ToString()); Console.ReadLine(); CloseHandle(diskHandle); Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); return; } */ Console.WriteLine(""); } // Chiude lo stream CloseHandle(diskHandle); Console.ReadLine(); }![]()

Rispondi quotando