Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 28, 2025

Find-OpenFile -FilePath <directory> throws "Could not list processes locking resource. Failed to get size of result." because the Windows Restart Manager API doesn't support directories.

Changes

  • FindOpenFileCommand.cs: Detect directory paths and route to new handler
  • WalkmanLib.GetFileLocks.GetAllHandles.cs:
    • GetDirectoryHandles() - enumerates handles matching directory or files within
    • GetProcessesLockingDirectory() - returns unique Process objects for matching handles
    • Device-to-DOS path conversion with thread-safe lazy initialization
  • Tests: New context for directory support scenarios
  • README.md: Added folder usage example

Implementation

For directories, uses the NtQuerySystemInformation/NtQueryObject approach instead of Restart Manager. Converts device paths (\Device\HarddiskVolume3\path) to DOS paths for matching.

# Previously threw error, now works
Find-OpenFile -FilePath C:\Test

# NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
# ------    -----      -----     ------      --  -- -----------
#     56    50.62      74.23      10.42   15136   1 notepad
Original prompt

This section details on the original issue you should resolve

<issue_title>Error when try to check an opened folder</issue_title>
<issue_description>Hi,
Thanks for your utility!
When I try to check if a folder is used by another process I got the following error:

Find-OpenFile : Could not list processes locking resource. Failed to get size of result.
At line:1 char:1
+ Find-OpenFile -FilePath C:\Users\sabramczyk\Documents
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Find-OpenFile], Exception
    + FullyQualifiedErrorId : System.Exception,FindOpenFiles.FindOpenFileCommand

I know that maybe the tool should check only files, but if I open a .txt file with notepad and check with Find-OpenFile I got nothing. if I check with handle.exe utility I got also nothing when checking the file but I got results when I check the folder:

PS C:\Users\sa> Find-OpenFile -FilePath C:\Test\test.txt

PS C:\Users\sa> C:\Tools\handle64.exe -nobanner "C:\Test\test.txt"
No matching handles found.

PS C:\Users\sa> C:\Tools\handle64.exe -nobanner "C:\Test"

notepad.exe        pid: 15136  type: File            44: C:\Test

# Error when try to check the folder
PS C:\Users\sa> Find-OpenFile -FilePath C:\Test
Find-OpenFile : Could not list processes locking resource. Failed to get size of result.
At line:1 char:1
+ Find-OpenFile -FilePath C:\Users\sabramczyk\Documents
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Find-OpenFile], Exception
    + FullyQualifiedErrorId : System.Exception,FindOpenFiles.FindOpenFileCommand

Can you make it support also folders?

Thank you!
Shayki</issue_description>

<agent_instructions>Please add support for folders. Add a parameter if it makes sense. Add tests to ensure that the functionality works.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@adamdriscoll Sure. I think that's a handy option!

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 28, 2025 12:41
Co-authored-by: adamdriscoll <1256531+adamdriscoll@users.noreply.github.com>
… exception handling

Co-authored-by: adamdriscoll <1256531+adamdriscoll@users.noreply.github.com>
@adamdriscoll adamdriscoll marked this pull request as ready for review November 28, 2025 12:45
Copilot AI changed the title [WIP] Fix error when checking an opened folder Add folder support for Find-OpenFile -FilePath Nov 28, 2025
Copilot AI requested a review from adamdriscoll November 28, 2025 12:46
@adamdriscoll adamdriscoll merged commit 389fb1c into master Nov 28, 2025
2 checks passed
@adamdriscoll adamdriscoll deleted the copilot/fix-open-folder-check-error branch November 28, 2025 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when try to check an opened folder

2 participants