Dariush Gavari
Dariush Gavari

Reputation: 27

Run Multi Program With Delay in batch file

i want run a program and then close that program after 30 sec.

i write a two batch files ,

first batch file is running the program. the program is Hotspot Shield.

the cod is

@ECHO off
"C:\Program Files (x86)\Hotspot Shield\bin\hsscp.exe"
timeout /t 30
"E:\1.bat"
Exit

the program is running fine, but after 30 Second the second batch file won't running .

the code of second batch file is

@ECHO off
cd "C:\Program Files (x86)\Hotspot Shield\bin"
Taskkill /IM "hsscp.exe" /F
Exit

when i add this command

timeout /t 30

before the this command in first batch file

"C:\Program Files (x86)\Hotspot Shield\bin\hsscp.exe"

the batch file counting down . but after that not counting down.

what is the problem?

i just want run the hotspot shield and after 30 second close that. windows is 10.

thanks

Upvotes: 1

Views: 4012

Answers (2)

Compo
Compo

Reputation: 38579

I'm not sure if it's still true but the Hotspot Shield executable used to accept a -quit parameter. If that's the case then it would surely be a better option than forcibly closing it with TaskKill.

This may well be worth a try:

@Echo Off
CD /D "%ProgramFiles(x86)%\Hotspot Shield\bin" 2>Nul || Exit /B
Start hsscp
Timeout 30 /NoBreak > Nul
Start hsscp -quit

Upvotes: 1

Magoo
Magoo

Reputation: 79982

@ECHO off
START "" "C:\Program Files (x86)\Hotspot Shield\bin\hsscp.exe"
timeout /t 30 >NUL
Taskkill /IM "hsscp.exe" /F
Exit

The ...hsscp.exe executable will start in a new process. The 30-second timeout will become silent because of the >nul and the current directory for taskkill is not relevant.

The first double-quoted argument in a start command is the window-title, so the extra pair of quotes in the start command provides an empty title.

Upvotes: 3

Related Questions