コード例 #1
0
 /// <summary>
 /// Function to Lock Volumes
 /// </summary>
 /// <param name="drive">Volume label</param>
 /// <returns>
 /// true on successful lock of the volumes,else false
 /// </returns>
 public bool LockVolume(string drive)
 {
     try
     {
         uint bytesWritten = 0;
         bool locked       = DeviceIO.DeviceIoControl(this.fileHandle, DeviceIO.FSCTL_LOCK_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesWritten, IntPtr.Zero);
         if (locked == false)
         {
             Console.WriteLine("\nCoudln't lock  volume\n");
         }
         return(locked);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
コード例 #2
0
 /// <summary>
 /// Function to Unmount Volumes
 /// </summary>
 /// <param name="drive">Volume label</param>
 /// <returns>
 /// true on successfull unmount of the volume, else false
 /// </returns>
 public bool UnmountVolume(string drive)
 {
     try
     {
         uint BytesWritten = 0;
         Console.WriteLine("\nAttempting to Unmount volume : " + drive + "\n");
         bool unmounted = DeviceIO.DeviceIoControl(this.fileHandle, DeviceIO.FSCTL_DISMOUNT_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, ref BytesWritten, IntPtr.Zero);
         if (unmounted == false)
         {
             Console.WriteLine("\nCoudln't Dismount  volume\n");
         }
         return(unmounted);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }