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

Researcher 96 Reputation points

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

0 comments No comments

Sign in to comment

Answer accepted by question author

Gade Harika (INFOSYS LIMITED) 2,850 Reputation points Microsoft External Staff

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.

  1. Gade Harika (INFOSYS LIMITED) 2,850 Reputation points Microsoft External Staff

    Hope you’re doing well. We’re following up on this thread to check if the issue is still occurring or has been resolved. If it has been resolved, kindly mark the answer as accepted by clicking the "Yes I agree" button post thread closure for better visibility to community members. If we do not receive a response from you, we will proceed with closing this thread by May 22th.

  2. Gade Harika (INFOSYS LIMITED) 2,850 Reputation points Microsoft External Staff

    Thank you for your response. We will now proceed with closing the thread as per your confirmation. If you encounter any further issues, please feel free to raise a new thread.


Sign in to comment

1 additional answer

  1. AI answer

    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:

    AI-generated content may be incorrect. Read our transparency notes for more information.
Sign in to answer

Your answer