I am trying to create a batch script that opens up 2 websites in iexplorer (I need to use IE).
Problem is, the urls are opened in separate IE windows.
Is it possible to just have 2 tabs in 1 window?
taskkill /im iexplore.exe /f
taskkill /t /f /im chrome.exe
taskkill /t /f /im communicator.exe
ping 127.0.0.1 -n 4
start iexplore.exe http://site1
start iexplore.exe http://site2
start communicator.exe
Use VBScript code to start a new InternetExplorer.Application and open the tabs using navigate2 method with navOpenInNewTab = 2048 flag:
#echo off
findstr /r /c:"^::[^ ]" "%~dpnx0" > "%temp%\openIEtab.vbs"
cscript //b //nologo "%temp%\openIEtab.vbs"
del "%temp%\openIEtab.vbs"
::set IE = CreateObject("InternetExplorer.Application")
::IE.visible = true
::IE.navigate2 "google.com"
::IE.navigate2 "bing.com", 2048
There are also powershell solutions (example).
Try adding a timeout right after the first website you're trying to open, like this. Timeout will wait whatever amount of seconds you set after the /T which might be what you're trying to accomplish with the ping command, unless you need to ping a specific address everytime.
taskkill /im iexplore.exe /f
taskkill /t /f /im chrome.exe
taskkill /t /f /im communicator.exe
ping 127.0.0.1 -n 4
start iexplore.exe http://site1
TIMEOUT>NUL /T 3 /NOBREAK
start iexplore.exe http://site2
start communicator.exe
Related
In short, I need to start 1.bat, that can CALL or START 2.bat to execute TASKKILL /im explorer.exe /f /t but keeps "1.bat" running (or reopens it) once "2.bat" is finished. The difficulty is, I need to keep the /t switch in TASKKILL to make it transferable.
Full Explanation:
I have several older laptops running Windows 7 x64. They will run games, but only if I use Task Manager to end Explorer, it's associated processes and stop several unneeded services. This frees up RAM and CPU to start games via Task Manager..
To avoid ending each process/service individually every time, I wrote 2 cmd batch files:
1) Options.bat -- (SHORTENED)
#echo off
:begin
echo (0) Kill Processes
echo (1) Run [game]
SET /p op=Select Task:
if "%op%"=="0" goto killall
if "%op%"=="1" goto op1
killall:
CALL "C:\TK.bat"
cls
goto begin
op1:
start " " /realtime "C:\[exe path]"
goto exit
:exit
exit
2) TK.bat -- (SHORTENED)
net stop [service]
taskkill /im explorer.exe /f /t
taskkill /im [specific process].exe /f /t
Both of which work as intended - provided I initially start Options.bat via Task Manager.
Problem: when I run Options.bat from Windows Explorer (even "Run As Administrator") and call the TK.bat script to run TASKKILL /im explorer.exe /f /t it does work, but also closes the CMD window, when i want it to return to the options selection. This does make sense when i'm using the "tree" attribute for TASKKILL.
However, if I run Options.bat via Task Manager, and CALL TK.bat, it will execute the commands (without closing itself) then return to the task selection - which is exactly what i want to happen!
I assume this is because it is running as the Local System account via Task Manager and not mine or the built in Administrator account?
I have tried the RUNAS command within Options.bat -
RUNAS /user:Adminstrator "C:\TK.bat"
which runs TK.bat, executes the TASKKILL command and then RUNAS again to return to the first batch file in my username. This does work, but I still have to press enter at each password prompt.
I have also tried numerous variations of the TASKKILL /FI switch:
TASKKILL /fi IMAGENAME ne cmd.exe /im explorer.exe /f /t`
TASKKILL /fi USERNAME eq [name] /fi WINDOWTITLE ne Options.bat /im explorer.exe /f /t
Which, I thought, would end all processes "not equal" to cmd.exe/Options.bat but I cannot get it to work.
Question: Is there a way of executing the TASKKILL /im explorer.exe /f /t within TK.bat, that will not close the currently running batch file and without having to run it from Task Manager? Perhaps a different command or giving the Options.bat some sort of elevated authority to stop it from being closed when Explorer.exe /t is ended. Ideally, without installing separate 3rd party tools?
I know I could edit the batch file to end explorer.exe, end each associated .exe and then stop the services I do not need, individually, but this is time consuming and defeats the point of writing the file to make it automated and transferable (if needed).
Any help would be greatly appreciated and I can upload the full code of both batch files, if that would help.
Strangely enough, the simple taskkill /F /IM explorer.exe & start explorer command does this task. I don't know why, but it works.
To prevent taskkill /im explorer.exe /f /t from killing the cmd instance which is executing your batch file, You need to break the parent-child relationship between that particular instance of cmd.exe and explorer.exe.
The trick is to use two extra instances of nested cmds. The first one launches the second one and terminates immediately so the second instance becomes an orphaned process which can not be determined as descendant of exeplorer.exe. At this point the second instance can safely execute taskkill /im explorer.exe /f /t
start "Chain breaker" /min cmd /d /c start "Orphaned Process" cmd /d /c Options.bat
The above can be used from Command Prompt or from another batch file.
You can also incorporate this technique directly in to the Options.bat file, But extra logic is needed for Options.bat to determine when to launch itself in nested cmd and when to execute the actual code.
A sample script demonstrating the concept would be:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "tokens=3 delims=:" %%L in ("%~0") do goto %%L
REM Reinvoke the batch file forcing it to jump to the :main label
start "Chain breaker" /min cmd /d /c start "Orphaned Process" cmd /d /c #"%~d0\:main:\..%~pnx0"
exit /b
:main
taskkill /im explorer.exe /f /t
echo I'm alive
pause
exit /b
I have below command and saved it as a .bat file.
taskkill /F /IM explorer.exe
start /realtime chrome.exe
now I want to add some further command so that upon closing google chrome Windows Explorer process gets started automatically.
use start /wait to wait until the started process is finished/exited. Then just execute explorer.exe
taskkill /F /IM explorer.exe
start /realtime /wait chrome.exe
explorer.exe
Note: I don't think, its a good idea to kill explorer or to start a browser as "realtime", but I see your point: being on a meager system you want to assign every available resource to the task to be done.
(But Chrome might not be the best choice in this case)
Try the following with administrator privileges
start /min taskkill.exe /f /im explorer.exe 2>nul >nul && start "" /wait "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" && start "" /wait /realtime "%windir%\explorer.exe" && start "" /realtime "%windir%\system32\taskkill.exe" /f /im cmd.exe <nul
This final part: start "" /realtime "%windir%\system32\taskkill.exe" /f /im cmd.exe <nul, can be replace by call some_bat.bat <nul with all commands that you need to run.
So i wrote this batch file.
I need to use some kind of random function to choose between 9 .exe fles.
One of those .exe files is "OPTION1.exe", so i'd like the batch to select from "OPTION2.exe, OPTION3.exe..." etc, which are all located in the same folder as the first one.
I'd like to know if it's possible and how to do it.
Thanks for your time.
#echo off
:loop
TASKKILL /F /IM "Software.exe"
TASKKILL /F /IM "Chrome.exe"
TIMEOUT /T 5
cd C:\Users\admin\Documents\Software
start Software
TIMEOUT /T 15
start OPTION1.exe
TIMEOUT /T 10
start connect.exe
TIMEOUT /T 15
cd C:\Program Files (x86)\Google\Chrome\Application
start Chrome.exe
TIMEOUT /T 400
TASKKILL /F /IM "Chrome.exe"
TIMEOUT /T 10
cd C:\Users\admin\Documents\Software
start disconnect.exe
TIMEOUT /T 15
cls
GOTO loop
set /a executable=(%random% %% 9) + 1
set "executablename=OPTION%executable%.exe"
echo %executablename%
should show you a random executable name OPTION1.exe .. OPTION9.exe
Well there are a few improvements that you can make to the code you provided. Here is the modified code:
echo off
cls
:loop
TASKKILL /F /IM Software.exe
TASKKILL /F /IM Chrome.exe
TIMEOUT /T 5
cd C:\Users\admin\Documents\Software
start Software.exe
TIMEOUT /T 15
start OPTION1.exe
start OPTION2.exe
start OPTION3.exe
TIMEOUT /T 10
start connect.exe
TIMEOUT /T 15
cd C:\Program Files (x86)\Google\Chrome\Application
start Chrome.exe
TIMEOUT /T 400
TASKKILL /F /IM Chrome.exe
TIMEOUT /T 10
cd C:\Users\admin\Documents\Software
start disconnect.exe
TIMEOUT /T 15
cls
GOTO :loop
I'm trying to write a program that will open Chrome, wait for a short period of time then close Chrome, and repeat. At first it was working and then it began to only start timeout if I closed Chrome manually. I've tried these two codes each had the same problem.
Code 1
cd C:\Program Files (x86)\Google\Chrome\Application\
:loop
chrome.exe https://www.website.com -incognito
timeout /t 200
taskkill /F /IM chrome.exe /T > nul
goto loop
Code 2
cd C:\Program Files (x86)\Google\Chrome\Application\
:loop
chrome.exe https://www.website.com -incognito
TIMEOUT /NOBREAK /T 200>NUL
taskkill /F /IM chrome.exe /T > nul
goto loop
My knowledge with Windows Batch is very limited, and I pieced this together with a lot of internet searches, so the problem is probably very simple and I'm just not experienced enough to see it. Thank you for your time!
Not sure why, but chrome.exe runs synchronously unless there is already another chrome.exe process running. The first time you ran, you probably already had chrome running, which is why your code worked asynchronously as expected. But then when you TASKKILL all the chrome processes, it becomes synchronous, and no longer works as you want.
This issue has been reported at http://www.dostips.com/forum/viewtopic.php?f=3&t=7242.
In your case, the solution is simple - just use START to restore the asynchronous behavior.
cd C:\Program Files (x86)\Google\Chrome\Application\
:loop
start "" chrome.exe http://www.dostips.com -incognito
timeout /t 200
taskkill /F /IM chrome.exe /T > nul
goto loop
Why does this close immediately ? is it becouse of ERROR?
I want it to kill umcs when it can
in cmd it terminates process than prompts
ERROR: The process "UCMS.exe" not found multiple times and again terminates process
for /L %i in (1,0,2) do #ping -n 2 127.0.0.1 >nul & taskkill /F /im "UCMS.exe"
Due to the bizarre nature of the batch parser, in batch files the for loop variable must be specified with two percent signs, like this:
for /L %%i in (1,0,2) do #ping -n 2 127.0.0.1 >nul & taskkill /F /im "UCMS.exe"