Skip to content

Commit

Permalink
- Improve performance using NtDll API to find locking information ins…
Browse files Browse the repository at this point in the history
…tead of Sysinternals Handle.
  • Loading branch information
PolarGoose committed Apr 29, 2024
1 parent 5285b5c commit e679608
Show file tree
Hide file tree
Showing 30 changed files with 519 additions and 360 deletions.
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
max_line_length = 150

[*.{xml,wxs, csproj, wixproj, config, sln, svg, manifest, json}]
[*.{xml,wxs,csproj,wixproj,config,sln,svg,manifest,json,yaml}]
indent_size = 2
12 changes: 5 additions & 7 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ on: push

jobs:
build:
runs-on: windows-latest
runs-on: windows-2022
steps:
- uses: actions/checkout@v3
- run: .\build.ps1
- uses: softprops/action-gh-release@v1
- uses: actions/checkout@v4
- run: ./build.ps1
- uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: true
files: Build/Release/Installer/*.msi.zip
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: Build artifacts
path: Build/Release/Installer/*.msi.zip
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
# ShowWhatProcessLocksFile
A simple clone of [PowerToys File Locksmith](https://learn.microsoft.com/en-us/windows/powertoys/file-locksmith) utility to discover what processes lock a specific file or folder that has the following advantages:
* Supports older versions of Windows

A simple clone of [PowerToys File Locksmith](https://learn.microsoft.com/en-us/windows/powertoys/file-locksmith) utility to discover what processes lock a specific file or folder.

## Advantages over File Locksmith
* Much faster
* Lightweight
* Supports older versions of Windows
* Doesn't require admin rights to be installed

## Screenshots

### Context menu

# Screenshots
## Context menu
<img src="doc/ContextMenu.png" width="70%" height="70%"/>

## Application
### Application

<img src="doc/Screenshot.png" width="70%" height="70%"/>

# System requirements
* Windows 8 x64 or higher (you might need to install [.Net Framework 4.6.2](https://dotnet.microsoft.com/en-us/download/dotnet-framework/thank-you/net462-web-installer))
## System requirements

# How it works
The application uses [Sysinternals Handle](https://learn.microsoft.com/en-us/sysinternals/downloads/handle) from the [Sysinternals-console-utils-with-Unicode-support](https://github.com/PolarGoose/Sysinternals-console-utils-with-Unicode-support) to get information about locking processes.
* Windows 7 x64 or higher (you might need to install [.Net Framework 4.6.2](https://dotnet.microsoft.com/en-us/download/dotnet-framework/thank-you/net462-web-installer))

## How to use

# How to use
* Download `ShowWhatProcessLocksFile.msi.zip` from the latest [release](https://github.com/PolarGoose/ShowWhatProcessLocksFile/releases).
* Run the installer. The installer will install this program to the `%AppData%\ShowWhatProcessLocksFile` folder and add a `Show what locks this file` Windows File Explorer context menu element.
* Use `Show what locks this file` File Explorer's context menu to select a file or folder
* To terminate a process, select it and open a context menu by clicking the right mouse button
* If you want to uninstall the program, use `Control Panel\Programs\Programs and Features`. Uninstaller will remove an integration with the context menu and all installed files.

# How to build
## How to build

* To work with the codebase, use `Visual Studio 2022` with a plugin [HeatWave for VS2022](https://marketplace.visualstudio.com/items?itemName=FireGiant.FireGiantHeatWaveDev17).
* To build a release, run `.\build.ps1` (`git.exe` should be in your PATH)
11 changes: 9 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Function CheckReturnCodeOfPreviousCommand($msg) {
Function GetVersion() {
$gitCommand = Get-Command -Name git

$tag = & $gitCommand describe --exact-match --tags HEAD
try { $tag = & $gitCommand describe --exact-match --tags HEAD } catch { }
if(-Not $?) {
Info "The commit is not tagged. Use 'v0.0-dev' as a version instead"
$tag = "v0.0-dev"
Expand Down Expand Up @@ -74,15 +74,22 @@ Info "Version: '$version'. InstallerVersion: '$installerVersion'"
Info "Build project"
& $msbuild `
/property:RestorePackagesConfig=true `
/property:MSBuildWarningsAsMessages=NU1503 `
/property:Configuration=Release `
/property:DebugType=None `
/property:Version=$version `
/property:InstallerVersion=$installerVersion `
/verbosity:Minimal `
/target:"restore;build" `
$root/$projectName.sln
CheckReturnCodeOfPreviousCommand "build failed"

Info "Run tests"
dotnet test `
--no-build `
--configuration Release `
$root/$projectName.sln
CheckReturnCodeOfPreviousCommand "tests failed"

RemoveFileIfExists "$publishDir/${projectName}.msi.zip"
Info "Create zip archive from msi installer"
Compress-Archive -Path "$publishDir/$projectName.msi" -DestinationPath "$publishDir/${projectName}.msi.zip"
4 changes: 2 additions & 2 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="build/nuget" />
<add key="globalPackagesFolder" value="build/nuget" />
<add key="repositoryPath" value="build/nuget"/>
<add key="globalPackagesFolder" value="build/nuget"/>
</config>
</configuration>
3 changes: 0 additions & 3 deletions src/App/Gui/Controls/ProcessInfoListViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ShowWhatProcessLocksFile.Gui.Utils;
using ShowWhatProcessLocksFile.LockFinding;

Expand Down
4 changes: 2 additions & 2 deletions src/App/Gui/Controls/ProcessInfoView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
<TextBlock Grid.Column="2" Grid.Row="0" Margin="5" FontSize="12">
<Run FontWeight="Bold" Text="{Binding Process.ProcessName, Mode=OneWay}" /> <LineBreak />
Pid: <Run Text="{Binding Process.Pid, Mode=OneWay}" />,
User: <Run Text="{Binding Process.UserNameWithDomain, Mode=OneWay}" />,
User: <Run Text="{Binding Process.DomainAndUserName, Mode=OneWay}" />,
<Run Text="{Binding Process.ProcessExecutableFullName, Mode=OneWay}" />
</TextBlock>

<ItemsControl Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="3"
ItemsSource="{Binding Process.LockedPath}"
ItemsSource="{Binding Process.LockedFileFullNames}"
Visibility="{Binding IsExpanded, Converter={StaticResource BooleanToCollapsedVisibilityConverter}}">
<ItemsControl.ItemTemplate>
<DataTemplate>
Expand Down
9 changes: 2 additions & 7 deletions src/App/Gui/Controls/ProcessInfoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace ShowWhatProcessLocksFile.Gui.Controls;

internal class ProcessInfoViewModel : ViewModelBase
internal class ProcessInfoViewModel(ProcessInfo process) : ViewModelBase
{
public ProcessInfo Process { get; }
public ProcessInfo Process { get; } = process;

private bool isExpanded;

Expand All @@ -18,9 +18,4 @@ public bool IsExpanded
OnPropertyChanged();
}
}

public ProcessInfoViewModel(ProcessInfo process)
{
Process = process;
}
}
1 change: 0 additions & 1 deletion src/App/Gui/Controls/ProgressBarWithTextView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ShowWhatProcessLocksFile.Gui.Controls"
x:Name="self"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance Type=local:ProgressBarWithTextViewModel, IsDesignTimeCreatable=False}">
Expand Down
2 changes: 1 addition & 1 deletion src/App/Gui/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:utils="clr-namespace:ShowWhatProcessLocksFile.Gui.Utils"
xmlns:controls="clr-namespace:ShowWhatProcessLocksFile.Gui.Controls"
mc:Ignorable="d"
x:Name="self"
x:Name="Self"
Title="{Binding Title}" Height="450" Width="800"
d:DataContext="{d:DesignInstance Type=local:MainWindowViewModel, IsDesignTimeCreatable=False}">
<Window.Resources>
Expand Down
1 change: 0 additions & 1 deletion src/App/Gui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Windows;
using ShowWhatProcessLocksFile.Gui.Utils;
using ShowWhatProcessLocksFile.Utils;
Expand Down
6 changes: 1 addition & 5 deletions src/App/Gui/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ShowWhatProcessLocksFile.Gui.Controls;
using ShowWhatProcessLocksFile.Gui.Utils;
using ShowWhatProcessLocksFile.LockFinding;
Expand All @@ -11,7 +7,7 @@ namespace ShowWhatProcessLocksFile.Gui;

internal class MainWindowViewModel : ViewModelBase
{
public string Title => $"""{AssemblyInfo.ProgramName} {AssemblyInfo.InformationalVersion}{(Elevation.IsUserAnAdmin() ? " (Admin)" : "")}""";
public string Title => $"{AssemblyInfo.ProgramName} {AssemblyInfo.InformationalVersion}{(Elevation.IsUserAnAdmin() ? " (Admin)" : "")}";

public RelayCommand RefreshCommand { get; }

Expand Down
1 change: 0 additions & 1 deletion src/App/Gui/Utils/BooleanToCollapsedVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
Expand Down
1 change: 0 additions & 1 deletion src/App/Gui/Utils/RelayCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Windows.Input;

namespace ShowWhatProcessLocksFile.Gui.Utils;
Expand Down
77 changes: 0 additions & 77 deletions src/App/LockFinding/HandleExe.cs

This file was deleted.

Loading

0 comments on commit e679608

Please sign in to comment.