DOS Coding
YouTube download helper

Want to download YouTube music with ease? Just create a new bookmark and add this one-liner as the URL:

javascript:var url = location.href;if ((/.*\.youtube\..*\/watch\?.*v=[\w\-]+.*/).test(url)){'' + url.match(/v=[\w\-]+/)[0]);}

In case you’d like to see the history of the script, click here. History is sorted by oldest ones first.


1. What does this script do?

Read More

JavaScript code to search on Google

1. Create a new bookmark and give it a name;

2. Copy the below code into URL field:''+prompt('Google').replace(/ /g, '+'))


Retrieve a string’s length with VBScript

Create a plain text file called strLen.vbs (we’ll assume this name), stringLength.vbs, length.vbs or len.vbs;

Copy these lines into it:

 if wscript.arguments.count < 1 then
  wscript.quit -1
end if
wscript.quit len(wscript.arguments(0))

And run it this way:

cscript //nologo strLen.vbs "%string%"

In which %string% is a variable containing a string.

Result will be stored in ERRORLEVEL.

Function: VBSOutput

"VBSOutput" does exactly the opposite of VBSInput: it sends a string to a pop-up box so the user can easily copy it (as it already appears selected).

vbsoutput str [strDescription] [windowTitle]

str - String to be displayed;
strDescription - A brief description for the above string;
windowTitle - Self-explanatory.

Remember: parameters in [brackets] are optional.

Run vbsoutput.cmd without any parameters for an instant syntax consult.

Example (within a FOR %a loop):
vbsoutput “%~sa” “Short Path for wget.exe” “SHORT PATH”

[Example Image]

Click here for the code.

Function: VBSInput

This function uses VBScript to prompt for user input, and it does that with a pop-up window. I.e., it uses a graphical interface.

vbsinput varName [text] [windowTitle] [defaultInput]

varName - Variable name you want to store input
text - Text to show in inputBox (a question, an instruction, anything you want). If it contains spaces, remember to enclose it in “double quotes”.
windowTitle - Self-explanatory; a title for the pop-up window.
defaultInput - This will be the default entry in case the user hasn’t any answer.

Parameters enclosed in [brackets] are optional.

vbsinput name¹ “What’s your name?”² Name³ ”%username%”⁴

The above example will generate a pop-up asking for user’s name, where:

(1) is the variable to have the input stored in, i.e., echo %name% will display whatever the user entered;

(2) is what will be displayed in the window;

(3) is the window title;

(4) is the default entry.

[Example Image]

Click here for the code.

JavaScript POP-UP code generator (Pure VBScript)

As I said on the previous post, this is the pure VBScript program to generate JavaScript code for pop-up windows. Use it for your e-mails, for instance.

 'Get site
do while x = 0
  site = inputBox("Type in or paste URL", "URL", "http://")
  if site = "" then
    choice = msgbox("Terminate program?", 32+4+4096)
    if choice = 6 then wscript.quit()
    exit do
  end if
'Get window height and width
wth = inputBox("Window width", "Width", "800")
if wth = "" then wth = "800"
hght = inputBox("Window height", "Height", "600")
if hght = "" then hght = "600"
'Return javascript
inputbox "JavaScript window code for" & vbCrlf & site & ":", _
         "JAVASCRIPT", "'" & site & _
         "','','status=1, height=" & hght & _
         ", width=" & wth & "')"  

I don’t know much of VBScript, but this one works flawlessly. Besides, it’s a lot faster than the batch version.

JavaScript POP-UP code generator

Do you like JavaScript pop-ups? This program will generate the code for any website you want. You can then copy the code and save as a favorite on your preferred browser.

@echo off
setlocal enableDelayedExpansion
color 2A
for %%v in (site wth hgh) do set %%v=
set /p "site=Type in or paste the URL: "
if not defined site goto eof
if not [%site:~0,7%] == [http://] set site=http://%site%
echo URL: %site%
set /p "hgh=Define window height (default 600): "
if not defined hgh set hgh=600
set /p "wth=Define window width (default 800): "
if not defined wth set wth=800
call :VBS "%site%" "%hgh%" "%wth%"

for %%v in (site wth hgh) do set %%v=
exit /b

>"%temp%\jscript.vbs" (
echo inputbox "JavaScript window code:", "JAVASCRIPT", "'%~1','','status=1, height=%~2, width=%~3')"
wscript "%temp%\jscript.vbs"
del "%temp%\jscript.vbs"
exit /b

The output is shown on a window similar to the function VBSOUTPUT that I wrote some time ago; easier to copy text.

Anyway, make sure you check the pure VBScript program that do the same job out: click here.

Factorial and Exponentiation

Have you ever thought, “why doesn’t DOS have an exponential calculation? Why do I have to manually multiply x by itself?”

Well, your problems are over. Here’s a code that’ll do the work for you:

@echo off
if "%~1" == "" exit /b
if "%~2" == "" echo %~1^^x?&exit /b
set /a "n=%~1"
for /l %%n in (2 1 %~2) do set /a "n*=%n%"
echo %n%

Run it directly from your command line. It takes exactly 2 arguments: the number you want to modify and the “modifier”.

Here are some examples:

C:\>expo 2 2

C:\>expo 2 3

C:\>expo 2 4

C:\>expo 2 5

C:\>expo 2 6

C:\>expo 2 7

C:\>expo 2 8

C:\>expo 2 9

Not only that, but I also wrote a script for Factorials calculation! However, it won’t take numbers greater than 12.

@echo off
if "%~1" == "" exit /b
for %%f in (0 1) do if "%~1" == "%%f" echo 1&exit /b
if %~1 GEQ 13 echo Type in a number ^<= 12.&exit /b
set /a "fact=%~1"
set /a "x=fact"

set /a "x-=1, fact*=x"
if %x% NEQ 1 goto while
echo %fact%

This one takes only one argument: the number to be modified.

Explaining the “while” loop: think of it as “while %x% NEQ 1 (::do the loop)”
It will do the action between “:while” and the IF statements until %x% equals 1.

Some output: 

C:\>fact 1

C:\>fact 2

C:\>fact 3

C:\>fact 4

C:\>fact 5

C:\>fact 6

C:\>fact 7

C:\>fact 8

C:\>fact 9

C:\>fact 10

Hope you like it.

Functions with VBScript

It’s been some time now (3 days max.) that I wrote 3 functions for DOS that works with I/O and VBScript. The main idea was to make something different to capture user input, and to output some simple strings.
(click on the images to enlarge ‘em) 


I’ve already tested it on XP (SP3) and on 7 (64b); it works flawlessly.

This one from above will get whatever you write on that field and have a variable set with it. In this case, I used a variable called name


This one is a bit simpler; it gets a string and send it as a parameter to the function. Just a message box, though.

And the last one:


It will capture a string as the first parameter and make it copyable through VBScript inputBox. Very useful for programs in which the user wants to copy something specific. I use it to retrieve folders and files shortnames.

Anyway, I’ll work a bit more on them (actually, I’m considering the idea of remaking vbsMsgBox), and may post their source-codes later.

Feedback is welcome; what do you think about them?

Plain text file typer (SendTo feature)

This one’s meant to use the Type command to make some plain text files readable without a third party software. Very useful for NFO files.

Once again, use it with the SendTo option.

@echo off
IF [%1] == [] goto END
title Plain Text File Typer by DOS Coding
::script by Fawers
type %1|more /e


To know more about the more command (no pun intended), type more /? in Command Prompt.

As you might have seen, if no file is selected, the program will be terminated (2nd line of code).