01/02/2019 Notice: Due to life, besides a few fixes/updates listed for the scripts below, this repository will not be receiving updates until further notice. Note: Repo is available for adoption
- duration.cmd
- h2p.cmd
- hhmmss.min.cmd
- lazyJson.bat
- md5.cmd
- RemoveEmpties.bat
- slen.cmd
- etc
description: An expository collection of mysterious, and random Windows Batch/Cmd scripts
- When are quotes required?: [
cmd.exe /?
]
<space>
&()[]{}^=;!'+,`~
- What math operations can I do with
set /a "result=math"
- for expanded info see:
set /?
. Here is a summary: [set/?|findstr/rC:" .[&-]"
]
- for expanded info see:
() - grouping
! ~ - - unary operators
* / % - arithmetic operators
+ - - arithmetic operators
<< >> - logical shift
& - bitwise and
^ - bitwise exclusive or
| - bitwise or
= *= /= %= += -= - assignment
&= ^= |= <<= >>=
, - expression separator
- Underwhelmed/Overwhelmed? gist nibbles
Most scripts are agnostic to delayedExpansion, should be able to use !
- ah.fu.cmd -- Grossly overengineered process killer which reads a conf file to change behavior
- eph.u.conf -- dubbed "process-hitlist" is an example of a conf for ah.fu.cmd
- compactor.cmd -- wrapper around the windows binary compact.exe to compress/uncompress files via the NTFS filesystem
- Can walk down a directory tree and uncompress all files with a 1.0 ratio
- Full args parse
compactor -i C:\Windows\Temp\PowerPlan.log -u
compactor.cmd:unCompressExtensions: 05/28/18 23:28:34: PowerPlan.log: 0 files within 1 directories were uncompressed.
compactor -i C:\Windows\Temp\PowerPlan.log -z
compactor.cmd:unCompressRedundant: 05/28/18 23:28:47: PowerPlan.log: 0 files within 1 directories were uncompressed.
compactor -i C:\Windows\Temp -r -e .log -c
compactor.cmd:CompressExtensions: 05/28/18 23:31:13: C:\Windows\Temp\HighPerformancePlan.log: The compression ratio is 1.8 to 1.
compactor.cmd:CompressExtensions: 05/28/18 23:31:14: C:\Windows\Temp\PowerPlan.log: The compression ratio is 1.0 to 1.
compactor.cmd:CompressExtensions: 05/28/18 23:31:14: C:\Windows\Temp\vmware-SYSTEM\vmware-usbarb-1111.log: The compression ratio is 1.2 to 1.
compactor.cmd:CompressExtensions: 05/28/18 23:31:15: C:\Windows\Temp\vmware-SYSTEM\vmware-usbarb-2222.log: The compression ratio is 1.2 to 1.
compactor.cmd:CompressExtensions: 05/28/18 23:31:15: C:\Windows\Temp\vmware-SYSTEM-123456789\vmware-usbarb-3333.log: The compression ratio is 1.5 to 1.
compactor.cmd:CompressExtensions: 05/28/18 23:31:16: C:\Windows\Temp\vmware-SYSTEM-123456789\vmware-usbarb-4444.log: The compression ratio is 1.1 to 1.
- duration.cmd -- calculates execution duration and dumps summary
- simple calling syntax such as:
duration.cmd timeout /t 5
- dumps results/summary as a json object. Specific data/information is toggled via variables
- no external dependencies required, but uses these standard windows binaries when found:
- cmd.exe: launches command(s) as subprocess of cmd.exe
- timeout.exe: optional script execution sleep
- w32tm.exe: supplies timezone and DST
- simple calling syntax such as:
- elevate -- self-elevate scripts, functions and examples using "bunction" labels
- elevate/elevate.cmd -- elevates all passed arguments or starts a elevated cmd console
- elevate/elvn.cmd -- self-elevate using "bunction" oneliner; detection via "net session"
- elevate/elvc.cmd -- self-elevate using "bunction" oneliner; detection via "calcs"
- fLines.cmd -- prints file line counts using native find.exe
- runs fairly quick
- when directory, prints line counts for all the normal files in that directory
- simple syntax:
flines.cmd "%SystemRoot%\DirectX.log" C:\Windows\Logs\CBS\CBS.log
13967 : C:\Windows\DirectX.log
6431 : C:\Windows\Logs\CBS\CBS.log
- gmt.cmd -- Display the current date and time in GMT (World Time).
- queries wmic for time information
- This is a simplified/modified version. Original script/code: ss64.com
gmt.cmd
2018-07-21 13:54:07
- gstr.cmd -- batch native random string genarator.
- h2p.cmd -- grabs pdfs of url address using "wkhtmltopdf.exe".
- Code has been mostly scrubbed and unused functions have been removed.
- Names pdf file with urlstring+currentdateStamp
- ASCII encoded URL names decoded for auto-filename generator
- Support for special characters in URL namespace
- hhmmss.cmd -- Converts time: from total-seconds into hh:mm:ss notation - "Complete Edition"
- hhmmss.min.cmd -- Converts time: from total-seconds into hh:mm:ss notation - without all the "tard" code
- lazyJson.bat - Prints all key/value pairs to console
example of a "working" json object:
echo/{ "myVariable" : "some kind of string or integer" }> lzj.json
lazyJson.bat lzj.json
"myVariable=some kind of string or integer"
Usage: lazyJson.bat Summer\atLake\Jason.json "SomeFile OuttaSpace.json" fail3.json
Prints all key/value pairs to console
TL;DR -- NEEDS to have a whitespace on AT LEAST ONE side of the colon. Each key/value pair needs to be on a separate line
Note:
a space before/after a colon, and brackets -- { "key" : "value" }
\n and \r\n are considered end-of-key-value
makes no distinction between an [array] and {key:value} and considers \r\n[array]\r\n as a valueless key
commas outside double-quotes are ignored
- md5.cmd -- hashes files and directories with optional recursion, unicode and logging options
- mvlinks.bat -- Recursively moves directory tree
- Moves all: files, directories and hardlinks
- Recreates hardlinked files during move.
- Unhide/Rehide objects during move.
- For now, requires sysinternals "findlinks.exe" to expose all hardlinks.
- DOES NOT remove the old tree on purpose
- DOES NOT move/update junctions or symlinks
- pidArray.cmd -- uses
tasklist.exe
to print full/matched processList -- "pid" : "processName.ext"- Simple FIFO ArgsParse
- optionally prefixed keynames:
/?
,-v
,\h
,--help
,version
- parameters used as processname filters, see
tasklist
- optionally prefixed keynames:
- Simple FIFO ArgsParse
pidArray cmd*
"6168" : "cmd.exe"
"4976" : "cmd.exe"
pidArray
"0" : "System Idle Process"
...
"5768" : "tasklist.exe"
pidArray|sort
"0" : "System Idle Process"
...
"996" : "winlogon.exe"
pidArray NotRealProcess
INFO: No tasks are running which match the specified criteria.
- pidme.cmd -- Launches command and returns it's PID using powershell
- raw2res.bat -- Uses ffmpeg.exe to duplicate same images with different base heights
- depends on ffmpeg.exe
- slength.cmd -- Uses findstr.exe to calculate length of a string or the length of a variable's value
- slen.cmd -- minimized version of slength.cmd
- slength.cmd: string and variable examples:
slength.cmd "this is my super long string"
28
set "abc=0123456789"
slength.cmd abc
10
- subExport.bat -- Uses ffmpeg.exe dump/export/save all textbased subtitles from video containers (like .mkv)
- depends on ffmpeg.exe
- dump/clean ffmpeg subtitle error/export log files
- no support for image-based subtitles
- simple/efficient/robust args parser
- simple file extension and subtitle type filtering
- saves files as {vidoeFileName.extension}.{langId}.{streamId}.{subExtension}
- when langId is undefined, uses 'und' as langId
- creates the following subtitle files FOR EACH streamId: .ass, .srt, .vtt
- default path recursion. Unable to change this behavior at the moment. Not super efficient, but works.
- RemoveEmpties.bat -- Removes Empty Files/SubDirectories from the defaulted/given path(s)
- My use-case: remove leftover files/dirs from the temp directories
- determines whether file is empty (by file size)
- determines whether directory is empty. This detection is somewhat slow at the moment, I may improve the detection at a later date.
removeempties.bat -r "C:\dev\temp"
Info: Checking: "C:\dev\temp\tinyMM\templates\TvShowDetailExampleXml"
Info: Checking: "C:\dev\temp\tinyMM\templates\SimpleConfluence\include\images"
Info: Checking: "C:\dev\temp\tinyMM\templates\SimpleConfluence\include"
...
Del: Directory: "C:\dev\temp\nirsoft_logs"
Info: Remove Count Summary:
15 Dir(s)
131 File(s)
- unixTime.bat -- returns the current system time as unix time (01/01/1970 )
- Adjusts to system timezone and DST (or any other time adjustments registered with windows)
- Returns unixTime in Seconds OR milliseconds, option defined in 'user settings' inside the script
- Auto calculates leap-year(s)
- Optimized for quick execution. Runs 30%-50% faster when all comments/empty lines are removed
- unixTimeFull.bat -- returns the current system time as unix time (01/01/1970 )
- Same as unixTime.bat, but without the optimizations.
- Uses functions for further customization
- uptime.cmd -- returns system uptime
- depends on wmic for boot and current time
- quick customized output behavior (based on variables in the
User Config
section)
uptime.cmd
217:19:14
uptime.cmd
9d 01:19:14
uptime.cmd
9 days 1 hours 19 minutes 14 seconds