Answer accepted by question author
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.
-
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.
-
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
