microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
110.24k stars 6.49k forks source link

File LockSmith via commandline #22315

Open nutnutwin opened 1 year ago

nutnutwin commented 1 year ago

Description of the new feature / enhancement

Thank you for creating this feature

I went through documents https://learn.microsoft.com/en-us/windows/powertoys/file-locksmith and found no info on how to unlock folder using commandline(CMD)

Scenario when this would be used?

to unlock folder using programming

for example, in LockHunter https://lockhunter.com/

I can run in

C:\Program Files\LockHunter\LockHunter.exe "C:\Temp" to unlock folder

Supporting information

No response

jdfa commented 1 year ago

It would be also useful for me. I think outputting list of processes which is using current file is more important than killing some of them (taskkill can do that).

pranavpa8788 commented 1 year ago

+1 Agreed

mortl3000 commented 1 year ago

+1 would be also useful for me

xaviercarmo commented 1 year ago

+1, would also like this feature

joehom0416 commented 1 year ago

+1

simbarras commented 1 year ago

+1

David-Kyrat commented 1 year ago

+1 Edit: not needed anymore, I switched to Linux. It was easier. Although I highly support the adding of this kind of power user toys to Windows.

lwahonen commented 1 year ago

See my comments in https://github.com/microsoft/PowerToys/issues/28529

PZan commented 5 months ago

+1

cow1337killer3 commented 5 months ago

Need this so badly. Sysinternals handle is a piece of junk and doesn't work.

PolarGoose commented 4 weeks ago

There are already existing console tools

Don't they do what is asked?

lwahonen commented 4 weeks ago

The version I implemented has features like "wait until target process closes before returning", which is immensely useful in scripts.

PolarGoose commented 4 weeks ago

@lwahonen,

You can do that with a small PowerShell script:

param (
    [Parameter(Mandatory=$true)]
    [string]$PathToTheFileOrFolder
)

$handleInformation = & "$PSScriptRoot/handle64.exe" -accepteula -nobanner -v $PathToTheFileOrFolder
foreach($lockingProcess in ConvertFrom-CSV -Delimiter "," -InputObject $handleInformation) {
    Write-Host "Kill locking process: $lockingProcess"
    Stop-Process -Id $lockingProcess.Pid -Force

    Write-Host "Wait until the process is stopped"
    while (Get-Process -Id $lockingProcess.Pid -ErrorAction SilentlyContinue) {
        Start-Sleep -Seconds 1
    }
}

Also, Sysinternals Handle is more reliable. When run from an admin, it uses a kernel driver, PROCEXP152.SYS, to get the locking information.