1

I have been using the following command to try closing the notepad file "temp.txt" opened on the windows.

nircmd win close title "temp.txt"

But this command seems not to work. If I try the below code:

nircmd win close process notepad.exe

This will close all the notepad files opened.

So my question is why cant I close an instance of notepad based on the name of notepad windows using the title keyword? Is there any way to do this?

2

This command seems not to work

nircmd win close title "temp.txt"

The above doesn't work because temp.txt is not the full windows title, which is temp.txt - Notepad

You need to use either the full window title, or use stitle to match a partial title:

title: Finds the desired window by specifying the exact title of the window in [window to find] parameter.

stitle: Finds the desired window by specifying the first few characters of the window in [window to find] parameter.

(emphasis mine)

Source NirCmd Command Reference - win

window in the description for stitle refers to the window title.

The following commands both work:

rem use the full window title
nircmd win close title "temp.txt - Notepad"

rem use the first few characters of the window title
nircmd win close stitle "temp.txt"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.