How to lock or unlock a volume

static void LockVolume(string volume)
{
	using (DeviceIOControlHandle controlHandle = new DeviceIOControlHandle(volume, DeviceAccess.SendReceive))
	{
		if (!controlHandle.IsInvalid)
			controlHandle.Send(DeviceIOControl.FSCTL_LOCK_VOLUME);

	}
}

static void UnlockVolume(string volume)
{
	using (DeviceIOControlHandle controlHandle = new DeviceIOControlHandle(volume, DeviceAccess.SendReceive))
	{
		if (!controlHandle.IsInvalid)
			controlHandle.Send(DeviceIOControl.FSCTL_UNLOCK_VOLUME);

	}
}

...

LockVolume(@"\\.\X:");

...

Last edited Aug 29, 2011 at 10:00 PM by mfriedrich, version 1

Comments

No comments yet.