# batch that open/close link



## zmind (Jan 12, 2012)

hi guys, i have been searching around trying to find the commands for batch file (dont eve know if its possible) to do this :

open minimized explorer with a specific link, wait 1min then close explorer.

ex : start/min iexplorer http://www.google.com

just dont know if its possible the open/close in 1min lol

hope you guys can helpme


----------



## Squashman (Apr 4, 2003)

Need to know what version of Windows you are on.

In order to kill Internet explorer you will basically have to use TASKKILL or TSKILL. TASKKILL is not available on all versions of Windows but does make it easier to kill process because then all you need to know is the ImageName for the process. And of course Internet Explorers will be iexplore.exe
TSKILL doesn't allow you to use the Image name you have to use the PID in which case you would need to use TASKLIST to find the PID first and then use TSKILL to kill the task.


----------



## zmind (Jan 12, 2012)

i am running on windows 7

so could it be possible? but trough TASKKILL will close the specific explorer window that was open with the bat? or it will kill all already executed iexplorer.exe?

and about waiting 1min before it closes? this one i didnt find annything


----------



## Squashman (Apr 4, 2003)

You need to be more specific than Windows 7. XP Home did not have TASKKILL but XP Pro did. I am going to assume Windows 7 Home does not as well. But you could be a good little helper and open up a cmd prompt and type: *taskkill /?* and tell me if it gives you the help for the command.

It will kill all Internet Explorer Windows.

Since you are on Windows 7 you can use the TIMEOUT command to delay the script from executing the next command.
Type: *timeout /?* at the cmd prompt to see its usage.


----------



## Squashman (Apr 4, 2003)

Forgot that TASKKILL has a Window Title option. So if you are opening Google the Windows Title will say "Google - Windows Internet Explorer"

So with TASKKILL
TASKKILL /IM iexplore.exe /FI "WINDOWTITLE eq Google*"


----------



## zmind (Jan 12, 2012)

Great man, i didnt know about the "WINDOWTITLE eq Google*" part, great stuff 

but i think i found a way to do what i want (at least part lol)

@echo off
start/min iexplore http://www.google.com
set Delay=45

set killer=%temp%\kill.bat
echo > "%killer%" ping localhost -n %Delay% ^> nul
echo>> "%killer%" tasklist ^| find /i "iexplore.exe" ^> nul ^&^& taskkill /f /im iexplore.exe
start /b "Timeout" "%killer%"

it opens the explorer minimized, load for 45seconds and then closes!

Know that i did this part i am tryng to do the same several time, like this :

Open www.google.com for 45 seconds - close google

Open www.youtube.com for 45 seconds - close youtube

Open www.whatever.com for 45 seconds - close whatever

then return to the beginning (loop)

I tried several ways, but it opens the 3 windows at the same time lol


----------



## Squashman (Apr 4, 2003)

I have no idea why you are using a batch file to create another batch file. That is way to inefficient.

You don't need to use the PING delay on Windows 7. It has the TIMEOUT command which I mentioned in my previous posts. 

```
C:\Users\Squash>TIMEOUT /?

TIMEOUT [/T] timeout [/NOBREAK]

Description:
    This utility accepts a timeout parameter to wait for the specified
    time period (in seconds) or until any key is pressed. It also
    accepts a parameter to ignore the key press.

Parameter List:
    /T        timeout       Specifies the number of seconds to wait.
                            Valid range is -1 to 99999 seconds.

    /NOBREAK                Ignore key presses and wait specified time.

    /?                      Displays this help message.

NOTE: A timeout value of -1 means to wait indefinitely for a key press.

Examples:
    TIMEOUT /?
    TIMEOUT /T 10
    TIMEOUT /T 300 /NOBREAK
    TIMEOUT /T -1
```
You also don't need to pipe the TASKLIST command to the FIND command because you can use the filter option with the TASKLIST command to only output the IMAGENAME you want.

```
C:\Users\Squash>tasklist /FI "IMAGENAME eq iexplore.exe"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
iexplore.exe                  3628 Console                    1     20,748 K
iexplore.exe                  4256 Console                    1     57,012 K
```
You don't need to know if it is running to run the TASKKILL program to kill a process. If it can't find the process it just tells you it can't find it and moves on.

```
C:\Users\Squash>taskkill /f /im iexplore.exe
ERROR: The process "iexplore.exe" not found.
```
If you don't want to see the error message from not finding it then redirect standard error to NUL

```
C:\Users\Squash>taskkill /f /im iexplore.exe 2>nul
```
This boils down to the good old acronym K.I.S.S. Keep it simple stupid. You are way over thinking this.


----------



## Elvandil (Aug 1, 2003)

FWIW, I'm attaching a command-line executable that closes windows based on window name. Since it actually closes the program rather than "killing" it, there is no data loss if saving of history or session information is desired. Wildcards are allowed, too, such as:

close.exe Inter*

If not useful for this project, I have found it very useful for scheduled tasks that I want closed when they are done.


----------



## zmind (Jan 12, 2012)

But man i try the timeout function on windows 7 64b (pro) and doesnt recognize the coomand :/

So i used the other method, it seems to work on windows xp, vista and 7...but still i cant do the repeate website fuction, helpme out man lol


----------



## zmind (Jan 12, 2012)

i managed this batch :

@echo off

start/min iexplore http://google.com
PING 1.1.1.1 -n 1 -w 10000 >NUL
taskkill -IM iexplore.exe

@echo off

start/min iexplore http://youtube.com
PING 1.1.1.1 -n 1 -w 10000 >NUL
taskkill -IM iexplore.exe
EXIT

but now the last window (youtube) opens maximized?! why? lol
i tried several ways but gets always max...whats the problem? :/


----------



## zmind (Jan 12, 2012)

I have done it lol

@echo off

start/min iexplore http://google.com
PING 1.1.1.1 -n 1 -w 5000 >NUL
taskkill /F -IM iexplore.exe

SET GONEXT=D:
%GONEXT%
start/min iexplore http://youtube.com
PING 1.1.1.1 -n 1 -w 5000 >NUL
taskkill /F -IM iexplore.exe

SET GONEXT=D:
%GONEXT%
start/min iexplore http://facebook.com
PING 1.1.1.1 -n 1 -w 5000 >NUL
taskkill /F -IM iexplore.exe
EXIT

yeah, now try to put this invisible


----------



## Squashman (Apr 4, 2003)

zmind said:


> But man i try the timeout function on windows 7 64b (pro) and doesnt recognize the coomand :/


Then you are not typing in the command correctly. I am on Windows 7 64 Bit as well and as you can see that it works for me because I posted the help for you.

Of course I am not really sure what the point of this exercise is. It really doesn't serve a practical purpose.


----------



## Squashman (Apr 4, 2003)

Both of these worked for me.

```
@echo off
for %%I in (http://google.com http://youtube.com http://facebook.com) do (
	start "%%I" /min "iexplore.exe" %%I
	TIMEOUT /T 10 >nul
	taskkill /F /IM iexplore.exe
)
pause
```


```
@echo off
for %%I in (http://google.com http://youtube.com http://facebook.com) do (
	start "%%I" /min "iexplore.exe" %%I
	PING 1.1.1.1 -n 1 -w 5000 >NUL
	taskkill /F /IM iexplore.exe
)
pause
```


----------

