DropLock – Unlock the locked file in Windows

During the deployment, sometimes I encountered the problem that the files are currently locked and the files can be overwritten. The deployment will then fail and I can’t configure out which process is currently locking the file. I do need a tool to unlock the file by killing the other processes but I just need a portable tool which doesn’t require an installation. Most of the available tool requires an installation so that they can manipulate the context menu on right mouse click to insert their options for unlocking. Therefore I write myself a very simple tool to list all processes accessing the file and kill them all.

1. Introduction

The source code for getting locking processes are very simple. I use Restart Manager Functions to read the info of locking processes out

private static uint StartSession()
	var res = RmStartSession(out var handle, 0, Guid.NewGuid().ToString());
	if (res != 0)
		throw new DropLockException("Could not begin restart session. " +
									"Unable to determine file locker.");
	return handle;

For building the UI, I use Material Design In XAML Toolkit to create a beautiful user interface.

For the MVVM Pattern, I use Caliburn.Micro to make the data binding between Views and ViewModels. In Views .xaml, we use the supported syntaxes of Caliburn.Micro for data binding

<Grid Grid.Row="1">
		<ColumnDefinition Width="60"></ColumnDefinition>
	<TextBox AllowDrop="True" cal:Message.Attach="[Event Drop] = [Action FilePathPreviewDrop($source,$eventArgs)]; [Event PreviewDragOver] = [Action FilePathPreviewDragEnter($source,$eventArgs)]; [Event DragEnter] = [Action FilePathDragEnter($source,$eventArgs)]" Style="{DynamicResource MaterialDesignFloatingHintTextBox}" materialDesign:HintAssist.Hint="File path" Text="{Binding Path=FilePath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
	<Button x:Name="OpenFile" Margin="0 1 0 0" Grid.Column="1" Width="50" Style="{DynamicResource MaterialDesignFlatButton}">
		<materialDesign:PackIcon Kind="FileFind" />

And in ViewModel, we use the NotifyOfPropertyChange for notifying changes from model.

public string FilePath
	get => _filePath;
		_filePath = value;
		if (File.Exists(_filePath))

public ObservableCollection<DropLockProcess> Processes { get; set; } = new ObservableCollection<DropLockProcess>();

2. Binary

Download: http://hintdesk.com/wp-content/uploads/Tools/DropLock.zip

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.