public static bool LockVolume(string volumeName, ILogger logger) { bool flag = false; IntPtr file = Win32Utils.CreateFile(volumeName, 3221225472U, 3U, IntPtr.Zero, 3U, 0U, IntPtr.Zero); if (file.ToInt32() != -1) { int lpBytesReturned; if (Win32Utils.DeviceIoControl(file, 589848, IntPtr.Zero, 0, IntPtr.Zero, 0, out lpBytesReturned, IntPtr.Zero) != 0) { flag = true; } else { logger.Warning("error locking volume: " + volumeName + " error: " + (object)Marshal.GetHRForLastWin32Error()); } Win32Utils.CloseHandle(file); } return(flag); }