Opening separate web windows using a batch file - batch-file

I would like a batch file to open separate internet windows in order to keep relevant information grouped without having a ton of tabs.
I can open a single internet window doing this:
#Echo Off
start chrome.exe
exit
I can open two separate windows doing this:
#Echo Off
start chrome.exe
start chrome.exe
exit
However, as soon as I add a web link to either of these, the window will not open. Instead, a new tab is created in whatever window was open first it would seem:
#Echo Off
start chrome.exe "www.Yahoo.com"
start chrome.exe "www.Google.com"
Exit
These commands will open separate windows if there are no URLs, but they will open a new tab for the link if you include the URLs, usually in the first window that is/gets opened...
I just discovered -new-window here.
I will try that and report back.

#Echo Off
start chrome.exe -new-window "www.Yahoo.com"
start chrome.exe -new-window "www.Google.com"
Exit
This is what I needed. It opens separate windows for each without adding new tabs to a different window.

Related

cmd - save command output in a parameter then open browser

I am writing a cmd batch script that runs a module called Docsify. I want to get the URL from its output and open it in a browser. The problem I have is:
It doesnt echo the output (basically just a blank display after calling the command)
I need to open it in a browser
(Worth mentioning though that when I manually open localhost:3000 in the browser, then the page actually loads fine. I am not sure why the cmd command isnt able to display the proper output)
Here is my code:
FOR /F "tokens=*" %%A IN ('docsify serve ./docsify') DO (
echo %%A
)
This is my EXPECTED output:
Serving C:\Users\me\Desktop\NodeJS\node_modules\doc-viewer\docsify now.
Listening at http://localhost:3000
But then as I've mentioned what I'm getting is just a blank display.
I also tried to just manually enter the command and force it to open localhost:3000
docsify serve ./docsify
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE https://localhost:3000
Then the docsify output is displayed in my console, as expected. But then I need my script to open IE and go to localhost:3000. It currently doesn't do that because it is 'listening' at port 3000 (it stays on this prompt until I terminate the cmd). Is there anyway I can call a command to open IE while docsify is listening?
Any thoughts?? Thanks!
I finally found a solution. Basically I run the docsify server through docsify serve on a separate cmd window then add a timer before opening localhost:3000 on the browser.
start cmd.exe /c docsify serve ./docsify
timeout /t 3
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE http://localhost:3000

how to automatically close tinyweb console after running from batch file

I'm using TinyWeb server.
I run it using a batch file START_tiny.bat:
c:
cd\
cd tiny
cd bin
tiny c:\tiny\root 8080
exit
The problem is that after tiny.exe is executed, the console won't close so it hangs here:
I can manually close the console window, and it will continue to run as expected, but I was just wondering if there was a way in the batch file to make sure it closes after the program is invoked.
EDIT:
the solution was:
cmd /c start tiny c:\tiny\root 8080
The Windows command processor cmd.exe halts processing of the batch file as long as tiny.exe is running and waits for its termination, even if this application is a GUI application not opening any window or opening a GUI window.
The command exit is not necessary at all and is just bad for debugging the batch file.
It would be better to use a shortcut file (*.lnk) to just start TinyWeb server. Target in properties of shortcut file would be C:\tiny\bin\tiny.exe C:\tiny\root 8080 and Start in would be C:\tiny\bin or C:\tiny\root or whatever should be the current directory on starting TinyWeb. No console window is shown on tiny.exe not being a console application which I don't know as not having downloaded and installed this application.
The command start can be used in a batch file for starting TinyWeb server as separate process by cmd.exe without waiting for its termination.
One of the following command lines could be used in the batch file:
start C:\tiny\bin\tiny.exe C:\tiny\root 8080
start /DC:\tiny\bin tiny.exe C:\tiny\root 8080
start /D C:\tiny\bin tiny.exe C:\tiny\root 8080
start "TinyWeb server" C:\tiny\bin\tiny.exe C:\tiny\root 8080
start "TinyWeb server" "C:\tiny\bin\tiny.exe" "C:\tiny\root" 8080
start "TinyWeb server" /D"C:\tiny\bin" tiny.exe "C:\tiny\root" 8080
start "TinyWeb server" /D "C:\tiny\bin" tiny.exe "C:\tiny\root" 8080
Open a command prompt, run start /? and read the output help for an explanation of the above command lines.
The parameter /D specifies the start in respectively current directory for the started executable. It can be specified immediately after /D or separated with a space from the switch.
Command start interprets first string in quotes as window title. For that reason it is necessary to explicitly specify a window title in double quotes on one of the other arguments is enclosed in double quotes even if no console window is opened because of started application is a Windows GUI application. An empty title string specified with just "" is enough for GUI applications started by command start as separate process.
The command line cd /D "C:\tiny\bin" can be used to change current directory to C:\tiny\bin even on current directory being on a different drive. The help output on running in a cmd window cd /? explains the parameter /D to change also drive if necessary and not only current directory on current drive.

When opening vscode using batch file, cmd opens and doesn't close

When trying to open vscode folder using a batch file, Visual Studio opens up with that folder, but also a cmd window pops up and does not go away if you use exit command.
#echo off
start code "C:\GitHub\TestApp\testapp"
exit
VSCode opens up correctly, but also this window opens
Using VSCode 1.52.1, the only way I could start it without having a cmd window open after exiting the batch script is:
explorer.exe "%userprofile%\AppData\Local\Programs\Microsoft VS Code\Code.exe"
Note: it does not involve opening a specific local directory to work with. But maybe you can find a solution such as saving the folder as a workspace or using Ctrl+R to open recent folders. Plus, if you work only within that directory / workspace, or use it right before closing VSCode, it will be opened automatically at the next launch.
That's because you are actually invoking the batch file code.cmd which is located at [VSCodePath]\bin\code.cmd. The code.cmd file in turn invokes the actual VSCode executable code.exe
When invoking a batch file (.BAT or .CMD) using the start command, a new instance of CMD process will be created to handle the execution of the batch file, But it invokes the CMD process with the /K switch rather than /C
For example start code.cmd executes cmd /k code.cmd
It is the /K switch that causes the new cmd to remain open after finishing the execution of the batch file.
To resolve, instead of supplying the batch file directly the to the start command, execute it by an explicit CMD invokation:
#echo off
start cmd /C code "C:\GitHub\TestApp\testapp"
exit
That CMD window is associated with the VSCode instance that you just opened. Attempting to close it will terminate the application you started. (in this case, VSCode)
The start xxx xxx... command opens up a new cmd terminal to perform its action. Even though a new prompt appears, which can be used as a normal terminal itself, the VSCode process is inexorably linked to it as the parent process.
If your goal is to not launch a separate cmd window, then run:
start code /b "C:\GitHub\TestApp\testapp"
which just runs the command in the same window. The VSCode window is still inexorably bound to the current cmd window and will close if the cmd window disappears, but at least another cmd window isn't launched.
Windows doesn't have the capability to launch a program in the background from the terminal.
If all described solutions did not work for you, try making an ordinary Windows shortcut to "C:\Users\username\AppData\Local\Programs\Microsoft VS Code\Code.exe" C:\path-to-project-folder-or-file.
Then call this shortcut in your .bat or .cmd script like that (assuming shortcut name is shortcut):
#echo off
start C:\path-to-shortcut-file\shortcut

How to open a window in fullscreen with batch

I made a batch file earlier with the code
start chrome.exe --profile-directory="Profile 1" http://drive.google.com
It opens google chrome to the page "Drive.google.com" as the profile 1 user.
However, everytime i run it it opens chrome in a tiny window. I was wondering if there was a way to open it in either fullscreen mode or a larger windowed mode. I tried the
mode con lines=1000 cols=1000
But it seems to be only for batch files. Is there a variable simlilar to the profile variable that will open it in fullscreen?
As waeswaes said you can add the /max tag
/MAX Start window maximized.
So:
start /max chrome.exe --profile-directory="Profile 1" http://drive.google.com

batch-file - batch file to check for open browser script

Right now I have a batch file I created that simple kills a chrome browser and opens up a new one to a particular homepage. I run this on a 5 minute interval with some added software that runs it if there is no activity for 5 minutes. I use this as a timeclock.
I am having some issues with the browser closing and reopening all the time. I figure I can make this script more effiecent by changing a few things.
Instead of closing and open a new browser every 5 minutes I would like to check first if the chome browser is already open and if it is then simple refresh it, otherwise open it.
Here is my current script
#echo off
taskkill /f /im chrome.exe
start "chrome" "C:\Program Files\Google\Chrome\Application\chrome.exe" --kiosk "http://www.example.com/sd/clockin/testclockin.php"
To check if Chrome is currently running, you can use the tasklist command.
tasklist | findstr chrome.exe || echo Chrome is not running
the code after || will only run if an errorlevel is set by the previous command, i.e. if chrome.exe doesn't show up in tasklist. You can use && to execute only if an errorlevel was not set.
You can also just check the errorlevel using a simple if statement -
if %errorlevel%==1 echo Chrome is running
Obviously chrome is closing because you are running the taskkill command. I assume you want to refresh the open page. You may need to look into using VBScript for this. This should help - refresh firefox from .bat file/ command.

Resources