How can I use Handle.exe with Windows PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-2019210%22%20slang%3D%22en-US%22%3EHow%20can%20I%20use%20Handle.exe%20with%20Windows%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2019210%22%20slang%3D%22en-US%22%3E%3CP%3ENobody%20is%20helping%20and%20I%20can't%20solve%20this%20problem.%20I%20want%20to%20remove%20any%20that%20has%20a%20handle%20on%20Notepad.exe.%20I%20know%20how%20to%20run%20sysinternal%20handle.exe%20in%20this%20url%20source.%20But%20I%20am%20coding%20a%20software%20and%20I%20want%20to%20execute%20an%20automatic%20code%20with%20powershell%20and%20do%20it%20with%20a%20single%20code.%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Ftr-tr%2Fsysinternals%2Fdownloads%2Fhandle%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Ftr-tr%2Fsysinternals%2Fdownloads%2Fhandle%26nbsp%3B%3C%2FA%3EHow%20can%20I%20close%20a%20handle%20I%20want%20with%20Windows%20Sysinternals%20Handle%20v4.22%3F%20Example%3A%20Notepad.exe%20%26gt%3B%20Handles%20%26gt%3B%20C%3A%5CUsers%5Cdream%20%26gt%3B%20Close%20%26gt%3B%20Happy%20end%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20close%20all%20C%3A%5CUsers%5Cdream%20handles%20open%20on%20Notepad.exe.%3C%2FP%3E%3CP%3EBut%20I%20want%20to%20do%20this%20using%20the%20handle.exe%20via%20powershell.%20How%20can%20I%20do%20this%20with%20a%20single%20code%3F%20Please%20help.%20%3A(%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2019210%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Visitor

Nobody is helping and I can't solve this problem. I want to remove any that has a handle on Notepad.exe. I know how to run sysinternal handle.exe in this url source. But I am coding a software and I want to execute an automatic code with powershell and do it with a single code. https://docs.microsoft.com/tr-tr/sysinternals/downloads/handle How can I close a handle I want with Windows Sysinternals Handle v4.22? Example: Notepad.exe > Handles > C:\Users\dream > Close > Happy end

 

I want to close all C:\Users\dream handles open on Notepad.exe.

But I want to do this using the handle.exe via powershell. How can I do this with a single code? Please help. :(

 

v1.png

1 Reply

@dreamfancy 

From what I try to understand, you are trying to get the executed command (command id) from a process and perform an action against it, such as a notepad open a file called C:\users\dream, you want to close the notepad.

if so, you can use the WMI Object

Get-WmiObject Win32_Process | select name, commandline