.NET: Microsoft Technologies based on the .NET software framework. Runtime: An environment required to run apps that aren't compiled to machine language.
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.