Page 1 of 1

Close program without killing process

Posted: 10 May 2010 09:06
by millercj
Is there a way to close a program with a batch file without directly killing the process.

I want my batch file to close a program but if you kill the task, the next time when you open that application it thinks something bad happened and asks to send some information to the developer. Is there any way to skirt this?

Re: Close program without killing process

Posted: 10 May 2010 13:33
by aGerman
I don't know another possibility with native batch. But you could try to implement a small VBScript for simulating the short cut "Alt+F4".
Firefox as an example
*.bat

Code: Select all

@echo off &setlocal

set "process=firefox.exe"

for /f "tokens=2" %%i in ('tasklist /nh /fi "imagename eq %process%" 2^>nul') do set /a PID=%%i
if defined PID (
  >"%temp%\close.vbs" echo Set oSh = WScript.CreateObject^("WScript.Shell"^)
  >>"%temp%\close.vbs" echo oSh.AppActivate %PID%
  >>"%temp%\close.vbs" echo WScript.Sleep 200
  >>"%temp%\close.vbs" echo oSh.SendKeys "%%{F4}"
  >>"%temp%\close.vbs" echo Set oSh = Nothing
  cscript //nologo "%temp%\close.vbs"
  del "%temp%\close.vbs"
)


Regards
aGerman