From 5285b5cfee54ce36edc02955f93e51a93c5b5fe2 Mon Sep 17 00:00:00 2001 From: PolarGoose <35307286+PolarGoose@users.noreply.github.com> Date: Sat, 16 Sep 2023 19:17:26 +0200 Subject: [PATCH] - Enhance locking info retrieval using patched Sysinternals Handle utility. - Display the username for each process. - Allow the tool to run without admin privileges. - Introduce a button to restart the app in an elevated mode. --- .github/workflows/main.yaml | 6 +- README.md | 17 +-- ShowWhatProcessLocksFile.sln | 4 +- .github/workflows/build.ps1 => build.ps1 | 4 +- src/App/Gui/Controls/ProcessInfoListView.xaml | 6 +- src/App/Gui/Controls/ProcessInfoView.xaml | 11 +- src/App/Gui/Icons.xaml | 30 ++++ src/App/Gui/MainWindow.xaml | 16 ++- src/App/Gui/MainWindowViewModel.cs | 19 ++- src/App/LockFinding/HandleExe.cs | 71 +++++++--- src/App/LockFinding/LockFinder.cs | 131 ++++++++++++------ src/App/LockFinding/Utils/CsvParser.cs | 19 +++ src/App/LockFinding/Utils/PathUtils.cs | 18 +++ src/App/ShowWhatProcessLocksFile.csproj | 22 +-- src/App/Utils/CommandLineParser.cs | 2 +- src/App/Utils/Elevation.cs | 26 ++++ src/App/Utils/ProcessKiller.cs | 6 +- src/App/app.manifest | 11 -- src/Directory.Build.props | 4 +- src/Installer/Installer.wixproj | 2 +- src/Installer/Product.wxs | 31 +++-- src/Test/LockFinderTest.cs | 56 -------- src/Test/LockFinding/LockFinderTest.cs | 80 +++++++++++ src/Test/Test.csproj | 16 ++- 24 files changed, 416 insertions(+), 192 deletions(-) rename .github/workflows/build.ps1 => build.ps1 (96%) create mode 100644 src/App/LockFinding/Utils/CsvParser.cs create mode 100644 src/App/LockFinding/Utils/PathUtils.cs create mode 100644 src/App/Utils/Elevation.cs delete mode 100644 src/App/app.manifest delete mode 100644 src/Test/LockFinderTest.cs create mode 100644 src/Test/LockFinding/LockFinderTest.cs diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 20ba469..1d95298 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -5,15 +5,15 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v3 - - run: .github/workflows/build.ps1 + - run: .\build.ps1 - uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: draft: true - files: Build/Release/*.msi.zip + files: Build/Release/Installer/*.msi.zip - uses: actions/upload-artifact@v3 with: name: Build artifacts - path: Build/Release/*.msi.zip + path: Build/Release/Installer/*.msi.zip diff --git a/README.md b/README.md index f15506d..a259f02 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # ShowWhatProcessLocksFile -A utility to discover what processes lock a specific file or folder. +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 +* Lightweight # Screenshots ## Context menu @@ -9,19 +11,18 @@ A utility to discover what processes lock a specific file or folder. # System requirements -* Windows 10 or higher (it can also work on Windows 8 if you install [.Net Framework 4.6.2](https://dotnet.microsoft.com/en-us/download/dotnet-framework/thank-you/net462-web-installer)) -* The user should be allowed to run applications as an Administrator. +* 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)) # How it works -The application uses [Handle2](https://github.com/PolarGoose/Handle2) to get information about locking processes. +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. # 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 programm to the `%AppData%\ShowWhatProcessLocksFile` folder and add a `Show what locks this file` Windows File Explorer context menu element. +* 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 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 files which were installed. +* 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 * 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 `.github\workflows\build.ps1` (`git.exe` should be in your PATH) +* To build a release, run `.\build.ps1` (`git.exe` should be in your PATH) diff --git a/ShowWhatProcessLocksFile.sln b/ShowWhatProcessLocksFile.sln index 3037700..fa79a9c 100644 --- a/ShowWhatProcessLocksFile.sln +++ b/ShowWhatProcessLocksFile.sln @@ -6,14 +6,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShowWhatProcessLocksFile", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "src\Test\Test.csproj", "{19D889E7-E728-4BFF-A68E-5445454F4417}" EndProject -Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "Installer", "src\Installer\Installer.wixproj", "{8D8AB22B-5677-4A21-B25F-75F2409248EC}" +Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "Installer", "src\Installer\Installer.wixproj", "{8D8AB22B-5677-4A21-B25F-75F2409248EC}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{A8406D94-94FD-4135-875A-1A0FF1E54DC5}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .gitattributes = .gitattributes .gitignore = .gitignore - .github\workflows\build.ps1 = .github\workflows\build.ps1 + build.ps1 = build.ps1 src\Directory.Build.props = src\Directory.Build.props .github\workflows\main.yaml = .github\workflows\main.yaml nuget.config = nuget.config diff --git a/.github/workflows/build.ps1 b/build.ps1 similarity index 96% rename from .github/workflows/build.ps1 rename to build.ps1 index 0f7084b..7c0460d 100644 --- a/.github/workflows/build.ps1 +++ b/build.ps1 @@ -61,9 +61,9 @@ Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $ProgressPreference = "SilentlyContinue" -$root = Resolve-Path "$PSScriptRoot/../.." +$root = Resolve-Path "$PSScriptRoot" $buildDir = "$root/build" -$publishDir = "$buildDir/Release" +$publishDir = "$buildDir/Release/Installer" $projectName = "ShowWhatProcessLocksFile" $version = GetVersion $installerVersion = GetInstallerVersion $version diff --git a/src/App/Gui/Controls/ProcessInfoListView.xaml b/src/App/Gui/Controls/ProcessInfoListView.xaml index 3629090..6a26325 100644 --- a/src/App/Gui/Controls/ProcessInfoListView.xaml +++ b/src/App/Gui/Controls/ProcessInfoListView.xaml @@ -20,8 +20,10 @@ Content="{StaticResource CollapseAll_icon}" ToolTip="Collapse All" /> - + diff --git a/src/App/Gui/Controls/ProcessInfoView.xaml b/src/App/Gui/Controls/ProcessInfoView.xaml index 8e2f452..80ca8b8 100644 --- a/src/App/Gui/Controls/ProcessInfoView.xaml +++ b/src/App/Gui/Controls/ProcessInfoView.xaml @@ -28,13 +28,16 @@ - + Pid: , - + User: , + - diff --git a/src/App/Gui/Icons.xaml b/src/App/Gui/Icons.xaml index bef0c1f..a408a12 100644 --- a/src/App/Gui/Icons.xaml +++ b/src/App/Gui/Icons.xaml @@ -174,6 +174,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/App/Gui/MainWindow.xaml b/src/App/Gui/MainWindow.xaml index 18b442c..fd69467 100644 --- a/src/App/Gui/MainWindow.xaml +++ b/src/App/Gui/MainWindow.xaml @@ -4,11 +4,15 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ShowWhatProcessLocksFile.Gui" + xmlns:utils="clr-namespace:ShowWhatProcessLocksFile.Gui.Utils" xmlns:controls="clr-namespace:ShowWhatProcessLocksFile.Gui.Controls" mc:Ignorable="d" x:Name="self" Title="{Binding Title}" Height="450" Width="800" d:DataContext="{d:DesignInstance Type=local:MainWindowViewModel, IsDesignTimeCreatable=False}"> + + + @@ -19,12 +23,20 @@ + -