PowerToys
PowerToys copied to clipboard
File Locksmith - command line version
Description of the new feature / enhancement
Make a command line version of file locksmith so it can be use in batch files.
Scenario when this would be used?
I have a batch file to open an excel file, but only if it is not already open. And after I open the excel file, my batch file waits for it to finish before doing more stuff.
because of the quirky way excel works when it has multiple files open, neither "start /wait" nor C:\Windows\System32\tasklist.exe can do the job.
Supporting information
"C:\Windows\System32\openfiles.exe /query" takes way too long.
"lsof" is a command in various flavors of unix that is like what I want. https://man7.org/linux/man-pages/man8/lsof.8.html
Lot's of other people want this too, as google will show you. https://www.google.com/search?q=how+to+check+from+command+line+if+a+given+file+is+open+by+any+process
I needed this acutely, so I added it to my fork ( https://github.com/lwahonen/PowerToys ). I'm happy to help get this merged upstream.
Usage:
"PowerToys.FileLocksmithUI.exe" <options> <files>
Options implemented:
/list Dump all current locks to the console /wait Only quit after all the locks to a file are gone /kill Try to kill every process holding a lock to the files listed /quit Close FileLocksmith after processing other options
For example
Ended up making a separate project for the console tool, updated my repo. Not sure how to get the ConsoleSmith.exe packed in the installer, but I'm happy to work with someone more knowledgeable
I would see if we couldn't just do this inside the UI and maybe adjust the UI exe name personally.
Big feedback here would be to if there is an alternative to "kill"
As I said in the other issue: Offering a command-line interface from a program built with subsystem:windows is a headache. You can reattach to the console that started you, but that still breaks things such as piping the output to a file - and scripts often redirect output of tools for reporting / further processing.
I'm very happy if someone has a magic trick in their back pocket that can be used to:
-Not show an extra console window when the application is started via icon -Output text to cmd if the application is started from the command line -Have said output be available for piping to files / other tools.
As to your other point, I'm happy to rename the command. Would terminate work better? That seems to be the term often used in Win32 APIs such as TerminateThread
Push it out the door the world needs it!
Push it out the door the world needs it!
I'm waiting for @crutkas to either suggest a way to integrate the command-line to the existing UI, or accept that the CLI is a separate tool.
@Langenbacher, There are already existing console tools for that:
- Sysinternals Handle. Note: it doesn't support Unicode file names. Take a fixed version from here
- Handle2
Would they work for you?
@Langenbacher, There are already existing console tools for that:
- Sysinternals Handle. Note: it doesn't support Unicode file names. Take a fixed version from here
- Handle2
Would they work for you?
I've been trying to use the original Handle for a while, it usually misses discovering some handles, especially when I'm trying to overwrite C++ DLL/output files. I've tried all the options, looking for handles on containing folders as well as the files.
But PowerToys Locksmith ALWAYS closes everything. It's just annoying to have to bring up the GUI, relaunch it in admin mode, click every button for each handle. It'd be a huge help if I could just add it to my IDE build options etc. It also seems like it goes a little overkill with closing handles that I don't think are actually locking the file. But at least it gets the job done.
Awesome job with your open-source program, I'll try it out and let you know how it goes. Thanks!
/dup https://github.com/microsoft/PowerToys/issues/22315
Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!