cklutz / lockcheck Goto Github PK
View Code? Open in Web Editor NEWUses platform APIs to find processes locking one or multiple files (Windows - Restart Manager or NTDLL)
License: MIT License
Uses platform APIs to find processes locking one or multiple files (Windows - Restart Manager or NTDLL)
License: MIT License
I've learned an interesting thing today:
you can't delete a directory which is a working directory of some running process on Windows. So if you get Access Denied when trying to delete a directory, check for a running process whose current directory is it.
We should consider extending LockCheck to iterate over running processes and check if there's a process whose current directory is the one we're asking about (or a subdirectory thereof).
GetLockingProcessInfos
with LockManagerFeatures.UseLowLevelApi
does not work if the path is a directory on windows.
The simplest example is getting the locks of a directory that is the working directory of a cmd/powershell window.
Windows 10 x64 on .NET 7
I've found this line from the documentation:
https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
Flag | Meaning |
---|---|
FILE_FLAG_BACKUP_SEMANTICS 0x02000000 |
You must set this flag to obtain a handle to a directory. A directory handle can be passed to some functions instead of a file handle. For more information, see the Remarks section. |
And then later in the same docs:
To open a directory using CreateFile, specify the FILE_FLAG_BACKUP_SEMANTICS flag as part of dwFlagsAndAttributes. Appropriate security checks still apply when this flag is used without SE_BACKUP_NAME and SE_RESTORE_NAME privileges.
So I think we should be using this flag if the path is a directory ๐
I would be interested to know how this compares to the approach mentioned by @KirillOsenkov in #6. The only case I can think of is that it would also be able to find locks on children of the directory, whereas this approach would not. Finding the lock of a child of a directory seems to be outside the scope of this library though.
Additionally, Restart Manager seems to not support finding locks on directories. Seems like another problem, but I thought I would mention it here.
I am interested in fixing it here because I'm currently using my fork of LockCheck in https://github.com/domsleee/ForceOps. For directories, I am currently just using NtDll (with UseLowLevelApi
).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.