Close program without killing process

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
millercj
Posts: 1
Joined: 10 May 2010 09:03

Close program without killing process

#1 Post by millercj » 10 May 2010 09:06

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?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Close program without killing process

#2 Post by aGerman » 10 May 2010 13:33

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

Post Reply