C# version of FSCTL_LOCK_VOLUME in DeviceIoControl not working

0

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!

c#
locking
pinvoke
asked on Stack Overflow Sep 6, 2013 by Dave Gordon

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0