Friday, 6 September 2013

C# version of FSCTL_LOCK_VOLUME in DeviceIoControl not working

C# version of FSCTL_LOCK_VOLUME in DeviceIoControl not working

I have the following code which for some reason keeps throwing up this
error: An attempt was made to reference a token that does not exist.
(Exception from HRESULT: 0x800703F0)
private bool LockVolume(SafeFileHandle handle)
{
int byteReturned;
const uint FSCTL_LOCK_VOLUME = 0x00090018;
if (DeviceIoControl(handle, FSCTL_LOCK_VOLUME, null, 0, null, 0,
out byteReturned, IntPtr.Zero))
{
return true;
}
else
{
// Failed to gain a lock.
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
return false;
}
}
Any ideas why this lock fails would be greatly appreciated!

No comments:

Post a Comment