Closing notepad.exe from the command line

  • Thread starter Thread starter kvp at ppg
  • Start date Start date
K

kvp at ppg

I am running several batch scripts on a shared remote
server via the NT Scheduler. The scripts run for several
hours each night. Since the scripts are running via
scheduler, a cmd window does not appear on the server
desktop. To prevent someone from cycling the server and
cancelling my script in mid-stream, I can display a
message in Notepad that shows on the server desktop
indicating that a job is running in the background using
the following command:

START notepad.exe processrunning.txt

Once the job has finished, how do I close the Notepad
showing on the desktop via the batch script?

Thanks
Kurt
 
kvp at ppg said:
I am running several batch scripts on a shared remote
server via the NT Scheduler. The scripts run for several
hours each night. Since the scripts are running via
scheduler, a cmd window does not appear on the server
desktop. To prevent someone from cycling the server and
cancelling my script in mid-stream, I can display a
message in Notepad that shows on the server desktop
indicating that a job is running in the background using
the following command:

START notepad.exe processrunning.txt

Once the job has finished, how do I close the Notepad
showing on the desktop via the batch script?

Thanks
Kurt
Start with a unique title and then use cmdow http://www.cmmandline.co.uk
to identify and close that notepad instance.

HTH
 
kvp at ppg said:
I can display a
message in Notepad that shows on the server desktop
indicating that a job is running in the background using
the following command:

START notepad.exe processrunning.txt

Once the job has finished, how do I close the Notepad
showing on the desktop via the batch script?


tskill notepad

All other notepad processes would end as well (if any
others exist)

--
Matt Hickman
He was still amused... by all the old stories about Earth--
what the Huff was "Earth," anyhow? -- but now realized that
such things could be taken seriously only by children and
dullards.
Robert A. Heinlein (1907 - 1988)
"Universe" c 1941 (ASF)
 
kvp said:
I am running several batch scripts on a shared remote
server via the NT Scheduler. The scripts run for several
hours each night. Since the scripts are running via
scheduler, a cmd window does not appear on the server
desktop. To prevent someone from cycling the server and
cancelling my script in mid-stream, I can display a
message in Notepad that shows on the server desktop
indicating that a job is running in the background using
the following command:

START notepad.exe processrunning.txt

Once the job has finished, how do I close the Notepad
showing on the desktop via the batch script?

Thanks
Kurt

Many ways to achieve this, here's but one example -

[SCRIPT]
@echo off

:: Current syntax requires 2000 Support Tools

:: Define the NOTEPAD FILENAME [no quotes]
set FN=test.txt

:: Define the KILL command and argument requirements
set KILL=kill -f

:: Prevent NOTEPAD from prompting for creation
:: of FILENAME if FILENAME does not exist
if not exist "%FN%" (
type nul >"%FN%"
)

:: Start NOTEPAD [remove echo statement below]
echo start "HELLO " notepad %FN%

:: Job runs here ["dir %windir% /s" used for example purposes]
dir %windir% /s >nul

:: Locate and destroy NOTEPAD process [remove echo statement below]
for /f %%p in ('tlist ^|findstr /i "notepad"^| findstr /i "%FN%"') do (
echo %KILL% %%p
)
[/SCRIPT]

HTH

Dean
 
Matthias Tacke said:
Start with a unique title and then use cmdow http://www.cmmandline.co.uk
to identify and close that notepad instance.
Provided no other window has that filename in the title:
for /F "tokens=1" %%A in ('cmdow /T /F^|find "processesrunning.txt"') do cmdow %%A /CLS

HTH
 
Back
Top