ZTree.com  | ZEN  | About...  

 Index   Back

[OT] How to close a file from command line   [OT]

By: Ben Kent       
Date: Nov 21,2013 at 16:25
In Response to: [OT] How to close a file from command line (Neil Clough)

> Hi All,
>
> I want to be able to close a specific file from the command line.
>
> e.g.
>
> I open the file "temp.txt" using:
>
> start "" notepad
> temp.txt
>
> and now I want to close just that file.
>
> Trawling on the net, I have found "taskkill", but I need to be able to
> find the file PID, otherwise I have to close all instances of notepad.
>
> e.g.
>
> taskkill /F /IM
> notepad.exe
>
> Any clues on how I can find the file PID ??
>
> Thanks

Don't need the PID, the window title can be used, like this

taskkill /fi "IMAGENAME eq notepad.exe" /fi "WINDOWTITLE eq temp.txt - Notepad"


But if you really want the PID, this will do it, remember to double the percent's for CMD, and quadruple for ZTree Application menu.

for /f "tokens=2" %I in ('tasklist /fi "IMAGENAME eq notepad.exe" /fi "WINDOWTITLE eq temp.txt - Notepad" ^| find /i "notepad.exe"') do set _PID=%I

Ben

1,236 views      
Thread locked
 

Messages in this Thread

 
96,640 Postings in 12,231 Threads, 350 registered users, 41 users online (0 registered, 41 guests)
Index | Admin contact |   Forum Time: Apr 16, 2024 - 6:32 pm UTC  |  Hits:62,885,262  (9,855 Today )
RSS Feed