internal static string GetDriveLabel(string drive) { StringBuilder sb = new StringBuilder(261); if (!NativeDisk.GetVolumeInformation(drive, sb, 261, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0)) { var exception = new Win32Exception(Marshal.GetLastWin32Error()); throw new Exception(string.Format("Error occured when trying to get drive label.\nError code: {0}\nMessage: {1}", exception.NativeErrorCode, exception.Message)); } return(sb.ToString()); }
internal static bool CheckReadOnly(string drive) { StringBuilder sb = new StringBuilder(261); FileSystemFeature flags; if (!NativeDisk.GetVolumeInformation(drive, sb, 261, IntPtr.Zero, IntPtr.Zero, out flags, IntPtr.Zero, 0)) { var exception = new Win32Exception(Marshal.GetLastWin32Error()); throw new Exception(string.Format("Error occured when trying to check if device is read only.\nError code: {0}\nMessage: {1}", exception.NativeErrorCode, exception.Message)); } return((flags & FileSystemFeature.ReadOnlyVolume) > 0); }