Batchography: How to check if your Batch file script is running as an Administrator

In chapter 4 of the Batchography book, I illustrate 3 methods that you can use to check if your Batch file script is running as an Administrator.

In this blog post, I will share with you the method entitled “Using known commands that fail to run without elevated privileges” from the book.

The idea behind this method is to run commands that are known to fail and return a non-zero error code if they are not executed with administrative privilege.

The Batch script would then check the return code and act accordingly:

@echo off


:: 
:: The Batchography book by Elias Bachaalany
::


net session >nul 2>&1

if %errorlevel% neq 0 (
  echo Requires administrative privilege.
  goto :eof
)

echo Script starts here...

flower separator
batchography-good-resDo you want to master Batch Files programming?

Look no further, the Batchography is the right book for you.

Available in print or e-book editions from Amazon.com!

 

flower separatorYou might also like:

Batchography: Changing the MAC address on Windows – A free Batch script

batchography-good-resIn a previous post entitled “How to get unlimited free Internet at Airports“, I showed you how to circumvent the time limit imposed by the “free” Wi-Fi connections in certain airports.

For that trick to work, you were required to update the MAC address of your computer each time the free time is over.

In this blog post, I am going to share with you the ChangeMACAddressBatch script that I wrote with the help and instructions from the excellent Batchography book.

The script makes use of various recipes illustrated in the Batchography book (in Chapter 4) and uses the various Batch scripting language syntax (Chapters 1 and 2) and methodologies (Chapter 3). Therefore, I will not be explaining the script’s contents or how it works because it will become evident if you read the Batchography book.

flower separator

Get the book from Amazon:

  • Paperback editionbtn-buy-on-amazon
  • E-book editionbtn-buy-on-amazon

flower separator

How to use the script interactively

To begin with, you need to run the script with administrative privileges.

Running the script as an administrator


On Windows 8 and above, just press Win+X and choose “Command Prompt (Admin)” like this:

chg-mac-run-elevated-command-prompt

Otherwise, if you are using the Windows Explorer window, then right-click on your script and choose “Run as Administrator”:

chg-mac-run-as-admin

Starting the script

When you first run the script, you will be presented with the main menu that will show you a list of all the adapters you have on your system.

On my laptop for instance, I have 4 adapters:

  • An Ethernet adapter
  • 2 x VMWare virtual adapters
  • A Wi-Fi adapter

Using the keyboard, type the adapter number that you want to inspect and/or change its MAC address:

chg-mac-main-menu

Let’s press “4” in this case and go inside that adapter’s information screen. Continue reading “Batchography: Changing the MAC address on Windows – A free Batch script”

Batchography: Building a dynamic menu in Batch files – Part 1

batchography-good-resIn this blog post, I am going to share with you a recipe from the Batchography book that illustrates and explains how to build a dynamic menu using the CHOICE command with Batch files. In this article, we will dynamically build a menu around the COLOR command so that the user can change the colors of the console interactively.

To learn more about this technique and the Batch scripting language, please refer to Chapters 3 and 4 in the Batchography book.

flower separator

Get the book from Amazon: the print editionbtn-buy-on-amazonor the e-book editionbtn-buy-on-amazon

flower separator

Continue reading “Batchography: Building a dynamic menu in Batch files – Part 1”

Batchography: Embedding an executable file in a Batch script

batchography-good-resIn this blog post, I am going to share with you a recipe from the Batchography book that illustrates and explains in details how to embed executable files in the Batch file script and execute them after they are dropped.

This technique does not rely on using a polyglot Batch file where its first part is actually a Batch script and the other part is a VBS or JScript script. If you want to learn more about how to write polyglot Batch scripts, please refer to Chapter 4 in the Batchography book.

flower separator

Get the book from Amazon: the print editionbtn-buy-on-amazonor the e-book editionbtn-buy-on-amazon

flower separator

Continue reading “Batchography: Embedding an executable file in a Batch script”

Batchography: Useful keyboard shortcuts for editing and working with the command prompt

batchography-good-res

In the Batchography book, not only you will learn about the command prompt’s keyboard shortcuts, macros and what not, but you will also learn the basic and fundamental topics for programming in the Batch language.

In this blog post, I present to you an excerpt from Chapter 1 in the Batchography book that covers all the useful keyboard shortcuts. My new favorite one is the F11 keyboard shortcut that is present in Windows 10 and up.

Get the book from Amazon: printed editionbtn-buy-on-amazonor the Kindle edition btn-buy-on-amazon. Continue reading “Batchography: Useful keyboard shortcuts for editing and working with the command prompt”

Introducing the “Batchography: The Art of Batch Files Programming” book

buy-from-amazonLong gone are the days when you had to use search engines to jump from one website to another in order to figure out the syntax or how to solve a problem using a Batch file script. The Batchography book is a boon for system administrators, build engineers, programmers and home users alike. It takes you on a journey of re-discovery of the lost art of Batch files programming. Whether you are an experienced user or new to the language, you will be surprised by the clarity and the abundance of the material presented in this book. With more than 140 scripting recipes, you will learn about things that you never thought were possible to achieve using the Batch files scripting language.

In the Batchography book, you will learn about:

  • The Basic concepts of Batch file scripting
  • Data structures: Arrays, Stacks, Sets, Maps
  • Multiline, compound and conditional statements
  • Function calls and repetition control structures
  • Files and strings manipulation techniques
  • Debugging and troubleshooting tips
  • Coding conventions and testing methodologies

Buy from Amazon:

How to show saved Windows 8 and Windows 10 Wifi passwords

In this blog post, I am going to illustrate how to reveal the saved Wifi passwords under Windows 8, 8.1 and Windows 10 in three easy steps.

flower separator
batchography-good-resDo you want to master Batch Files programming? Look no further, the Batchography is the right book for you.

Available in print or e-book editions from Amazon.
flower separator

Alternative method

You can just use the WifiPasswordReveal script to automatically reveal the saved password with a click of a button!

WifiPasswordReveal article

You might also like the following posts:

Step 1 – Open the Network and Sharing Center

Right click on the wireless networks icon in the tray bar (just next the clock):

image

Then right click on select “Open network and sharing center”

Step 2 – List all network adapters

Select “Change adapter settings”

image

This will give you a list of all available network adapters:

image

Step 3 – Show the WiFi properties and reveal the password

Double click on the Wifi card adapter icon for which you want to retrieve the password. In my case, I double-clicked on the “Wi-Fi” card.

The “Wi-Fi Status” dialog will show up. Press the “Wireless Properties” button:

image

Then switch to the “Security” tab:

image

Press “Show characters” to reveal the password.

I hope this short and concise article was useful. Please leave your comments or start following this blog to get notified about new / other useful tips.