2

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.

Dritzz
  • 159
  • 1
  • 1
  • 10
  • 1
    `-p` will resolve to the `-PipelineVariable` common parameter, remove it – Mathias R. Jessen Feb 22 '18 at 14:11
  • I've tried (&"D:\TeamCity\Handle\handle.exe" "–c C –p 3348 -y") still the same – Dritzz Feb 22 '18 at 14:13
  • 1
    External (ie not built into PowerShell) commands generally don't need any special handling try using `&"D:\handle.exe" –c C –p 3348 -y`: I suspect `handle` is looking for a process name "–c C –p 3348 -y". And putting only the parameters into quotes will pass them as a single parameter when they'll need to be separate – Richard Feb 22 '18 at 14:14
  • Thanks Richard, tried that as well but its not passing in any arguments into the handle exe. – Dritzz Feb 22 '18 at 14:17
  • Note: I can run the same Command Prompt command inside the Powershell Command window and get the same expected result as I did from the normal Command Prompt. – Dritzz Feb 22 '18 at 14:21
  • I've just tried `&"C:\bin\handle.exe" -p exp` and it worked fine from a 64bit PSH 5.1 console – Richard Feb 22 '18 at 14:26
  • yes that works for me was well but &"D:\handle.exe" –c C –p 3348 -y does not. So what am I missing. 'No Arguments will dump all file references' – Dritzz Feb 22 '18 at 14:29
  • `&"C:\bin\handle.exe" -p 2376 -c C98` just worked (but did require an elevated PSH) – Richard Feb 22 '18 at 14:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/165651/discussion-between-dritzz-and-richard). – Dritzz Feb 22 '18 at 14:33
  • I did get the "No arguments will dump all file references." error when trying to close a handle but specifying a process by name (to close handles you need the process id). – Richard Feb 22 '18 at 14:33

1 Answers1

2

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.

Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62