Share via

Is There Any Way to Identify the Process Locking a UNC File Without Administrator Permissions in .NET?

Researcher 76 Reputation points
2026-05-15T06:24:50.6266667+00:00

Description

I evaluated several approaches to identify the locking process, including SMB-based utilities such as Get-SmbOpenFile, Open Files (openfiles), and net file, Sysinternals handle.exe, and the Windows Restart Manager APIs through rstrtmgr.dll.. However, these mechanisms require admin permissions to retrieve reliable information.

The requirement is to identify the process locking a UNC file, regardless of whether the file is opened locally on the server or remotely through the network, from a normal non-admin .NET application.

Is there any supported or reliable approach that can provide this information without requiring administrator privileges?

Environment

Windows environment

UNC files

.NET application

Requirement is for non-admin/general application usage

Developer technologies | .NET | .NET Runtime
0 comments No comments

2 answers

Sort by: Most helpful
  1. Gade Harika (INFOSYS LIMITED) 2,765 Reputation points Microsoft External Staff
    2026-05-15T11:37:20.87+00:00

    Thanks for reaching out.
    There is no supported or reliable way for a non-administrator .NET application to determine which process is locking a UNC file.

    This is by design in Windows. Information about open file handles and locking processes is considered privileged system data, and access to it typically requires elevated permissions. Tools and APIs such as Get-SmbOpenFile, openfiles, net file, Sysinternals handle.exe, and even the Restart Manager API (rstrtmgr.dll) depend on administrative rights or are restricted to processes within the same permission scope.

    Additionally, for UNC paths, the locking information is often maintained by the server hosting the share, not the client machine. A standard user application cannot reliably query that information remotely.

    Within .NET, there is no built-in API that bypasses these OS-level security constraints. Any solution attempting to do so would either be incomplete or rely on elevated privileges.

    Recommended approaches:

    • Use server-side tools or APIs (e.g., SMB cmdlets) if administrative access is available
    • Implement application-level locking mechanisms (e.g., lock files or metadata tracking)
    • Use retry/backoff logic when encountering file locks
    • Optionally use the Restart Manager API for best-effort detection on local files (with limitations)

    In summary, due to Windows security design and SMB architecture, this requirement cannot be fully met from a non-admin .NET application.

    Please let us know if you require any further assistance, we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer". So that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    Was this answer helpful?

    0 comments No comments

  2. Q&A Assist
    2026-05-15T06:25:01.1633333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    No. There is no supported or reliable way for a normal, non‑administrator .NET application to enumerate which processes are locking a UNC file on Windows.

    All mechanisms that expose system‑wide file lock ownership (SMB server APIs like Get-SmbOpenFile, tools like openfiles, net file, Sysinternals handle.exe, or direct use of Restart Manager APIs) rely on privileges that ordinary users do not have. This is by design: identifying other users’ processes and their open handles is treated as privileged diagnostic information.

    Within .NET, the only supported helper in this area is Microsoft.Build.Utilities.LockCheck, which wraps the Windows Restart Manager API to report which processes are locking a given file. However, it only works on Windows and still depends on the underlying Restart Manager behavior and permissions; it does not bypass the administrative/privilege requirements and is not guaranteed to work for a non‑admin user against arbitrary UNC paths.

    Therefore, for a general‑purpose, non‑admin .NET application, there is no supported API or pattern that can reliably list the remote or local processes locking a UNC file. Any solution that appears to do so will either:

    • Be incomplete/unreliable (miss some lock owners), or
    • Depend on elevated rights or special server‑side components.

    References:

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.