Useful Windows 10 Batch Scripts

A batch file is a tiny script that you can execute on Windows. Think of it like executing a series of commands automatically through the command prompt or a shell script on Unix systems.

Useful Windows 10 Batch Scripts

A batch file is a tiny script that you can execute on Windows. Think of it like executing a series of commands automatically through the command prompt or a shell script on Unix systems.

The batch scripts that I use most often

Battery Report

Look at your battery status with one click.

REM @echo off 
powercfg/batteryreport
start "" chrome "%~dp0battery-report.html"
TIMEOUT 1
del battery-report.html

REM https://www.windowscentral.com/generate-battery-report-windows-10
  1. Generates a battery report in HTML at your current directory
  2. Opens that report in chrome
  3. Wait for a one second before deleting the report (to keep your directory clean)

This script uses the Windows-10 battery report feature. As featured on Windows Central, you can run the powercfg/batteryreport command to generate a report on your battery status.

Running the battery report command on the command line

Chrome App Mode

Run any web page like a local program

@echo off

color 0A

echo Open this link in distraction free chrome

SET /p input=Enter url: 

SET "stringAppParam=^-^-app^="
SET "finalParam=%stringAppParam%%input%"

REM Of course have to set the path of chrome first

START "" chrome %finalParam% --no-referrers
  1. Sets a cool matrix color scheme for this terminal session
  2. Takes in a URL and set it to the stringAppParam variable
  3. Opens the URL with the --app flag in chrome

This script uses the --app flag to launch any web page as a chrome app. It removes all the UI elements of chrome and only preserves the web view area. When using Slack or Discord, this might use less resources than their ElectronJS desktop app since there is no need to run a separate chromium and NodeJS instance (but of course, you miss out on their desktop app features and UI optimizations).

Running the batch file and using the Trello URL

You can customize it to open a specific web page:

START "" chrome -app=https://limxingzhi.github.io/pomodoro --no-referrers
Checkout my pomodoro timer web app

Youtube Borderless

Building on the chrome app script, we can play a Youtube video player without any distraction.

@echo off

color 4F

echo Open a youtube video in full window mode just like picture in picture XD

SET /p input=Enter video id: 

SET "stringAppParam=^-^-app^=https^:^/^/www^.youtube.com^/embed^/"
SET "finalParam=%stringAppParam%%input%"

REM Of course have to set the path of chrome first
REM https://www.maketecheasier.com/useful-chrome-command-line-switches/

START "" chrome %finalParam% --no-referrers --incognito
  1. Accepts the video ID (at the back of the URL)
  2. Run an embedded version of that video in app mode

By using an embedded frame, we can playback the video without any Chrome and Youtube UI. But some YouTubers does not allow their video to be played on embedded players, so this might not work for some channels.

Grab everything after the ?v=
Paste it in the command line
And wait for your video to buffer

Emptying Recycle Bin

Originally, I wanted to showcase a script that clears the recycle bin weekly. But Windows 10 introduced Storage Sense in Windows 10 last year. Now, we can clear the recycle bin weekly/monthly through the settings. No more batch scripts are needed for this.

Settings > System > Storage > Configure Storage Sense

Why use Batch Scripts?

Batch scripts cannot be compared to a full-fledged programming language like Python and pales in comparison to a Bash Shell Script. But on Windows, this is the best we've without installing any libraries or runtime.


References

Battery Report by Windows Central
https://www.windowscentral.com/generate-battery-report-windows-10

ElectronJS
https://electronjs.org/

Trello
I used this in a screenshot.
https://trello.com/

MKBHD's Video on the Surface Series
I used this in a screenshot.
https://youtu.be/omyZvH7aMtg

Storage Sense
The Storage Sense method for emptying recycle bin on Windows 10
https://techcommunity.microsoft.com/t5/Storage-at-Microsoft/Windows-10-and-Storage-Sense/ba-p/428270
https://www.ghacks.net/2019/04/12/how-to-empty-the-windows-recycle-bin-automatically/