Search code examples
powershellsysinternals

Sysinternal Close Handle working in Command Prompt But Not Powershell


I have a strange issue. I am trying to close down a handle using Powershell using this 1 liner:

(&"D:\handle.exe" -p "–c C –p 3348 -y")

I am getting the following response:

No matching handles found.

When I run the exact same command in Command Prompt

handle.exe -c C -p 3348 -y

I get:

Handle closed.

I am running Powershell and Command Prompt as Admin.

edit: Note: I can run the same command inside the Powershell Command Window and get the same expected result as I did from the normal Windows Command Prompt.


Solution

  • You don't need any fancy syntax. PowerShell can run command-line programs just like cmd.exe can. Just type the command you want and press Enter.

    handle -c C -p 3348 -y
    

    It is likely you need to run this from an elevated PowerShell window, but that's not different from cmd.exe.