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:

Technical cheat sheets

This article is compilation of the various blog posts that contain a set of steps, table of hotkeys and shortcuts and/or other quick information for reference purposes.
cheat sheet
The list below will be updated when new relevant articles are posted in this blog:

Stay tuned!

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”

Keyboard shortcuts for working in a remote desktop Windows Machine from your MacBook

macos-rdp-1In this blog post, I am going to share with you how to get the missing keyboard keys that let you work in MS Windows via the remote desktop client under Mac OS X with the MacBook’s keyboard.

What is important to know is that when using a MacBook’s keyboard, you don’t have all the keys that you usually have on a PC keyboard.

Essentially, you are missing the following keys:

  • HOME / END.
  • DEL key. This is different from the MacBook’s “Delete” key (which is equivalent to the “Backspace” key).
  • INS Key.
  • Page Up / Page Down.
  • The “Windows” key.

Continue reading “Keyboard shortcuts for working in a remote desktop Windows Machine from your MacBook”

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”

Kindle edition – Batchography: The Art of Batch Files Programming

buy-from-amazon

After one month of releasing the Batchography book, this month I released the e-book Kindle edition.

The benefits of the e-book Kindle edition is that you can buy the book from many countries in just a few clicks: USA, United Kingdom, Germany, France, Spain, Italy, Netherlands, Japan, Brazil, Canada, Mexico, Australia, India.
flower separator
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

Click here to see full details about the book.

Buy from Amazon: the print bookbtn-buy-on-amazonor the e-book btn-buy-on-amazon

flower separatorYou might also like:

 

WifiPasswordReveal: A script to reveal all the saved WiFi passwords in Windows 7 and above

Hello,

The “How to show saved Windows 7 Wifi passwords” turned out to be a popular article and to make the life of my readers easier, I decided to apply a newly acquired knowledge and write a tool to make it SUPER EASY to get all the saved WiFi passwords without needing administrative privileges and without having to click through various settings dialogs.

Note: In some cases, if the script fails to run, then you may want to run the script as administrator.

Read on! or download the script. Continue reading “WifiPasswordReveal: A script to reveal all the saved WiFi passwords in Windows 7 and above”

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:

Enable and use Bash under Windows 10

linux-subsystem-bash-coming-to-windows

Starting from Windows 10 build 14316 you will be able to use Bash from Windows, with the Ubuntu flavor without running a VM.

Bash will run natively on the OS without virtualization. It is implemented as new Windows subsystem.

In this article I will show you all the required steps to get Bash up and running in Windows 10! Continue reading “Enable and use Bash under Windows 10”

Backup and restore NTFS files permission with the ResetPermission utility

This is a follow up article to the popular article Resetting NTFS files permission in Windows – Graphical Utility.

In this article, I document the new feature in the ResetPermissions utility v1.1.5, where you can now backup and restore the NTFS files permissions. Continue reading “Backup and restore NTFS files permission with the ResetPermission utility”

Mouse Without Borders: Control up to 4 computers with one mouse and keyboard

mouse-without-borders-iconMouse without Borders is a prototype that makes you the captain of your computer fleet by allowing you to control up to four computers from a single mouse and keyboard. This means that with Mouse without Borders you can copy text or drag and drop files across computers. Mouse Without Borders is a Microsoft Garage project by Truong Do. Garage projects are side projects that Microsoft employees like Truong build for fun on their nights and weekends. Mouse Without Borders was designed for people who use many computers in the same room. For example, a laptop or tablet that you take to meetings might sit right alongside the desktop PC in your office.

I love this software. I use it whenever I have my laptop and desktop sitting next to each other. I can just use my desktop’s keyboard / mouse to control the laptop’s mouse and keyboard. The moment the mouse is moved away from one monitor, it crosses the borders to the other computer’s monitor. Not only that, any clipboard content will also transfer across borders. If I copy text or files on one machine, I can then paste them seamlessly on the second machine!

You can set up how your computer screens are laid out. For example, in the screenshot below, my desktop screen raised above the laptop who sits beneath it. Therefore, the moment I move my mouse from the computer’s screen all the way down, it then goes (across borders) to the laptop’s screen and activates the keyboard as well:

mouse-without-borders

It is very easy to set up and configure the “Mouse Without Borders” software. You can download it from Microsoft’s website here: http://aka.ms/mm.

flower separatorYou might also like:

 

Control Color Explorer: Explore your colors

As part of Windows apps development cycle, especially WinForms applications in Visual Studio, you may want to pick the right colors for your ListViews, Buttons, Labels, etc…

The best way to pick the colors is to visualize them.

With Control Color Explorer, you can visualize all the colors in the System.Drawing.Color type. You have the option to render the colors using the BackColor attribute or the ForeColor attribute:

color-explorer-bkg

Once you chose the colors you like, you may simply click the “Copy Color names”  to copy them and use them in your application.

You may grab the source code of this tool from my GitHub repository to compile it by yourself, or just download the binaries from here.

flower separatorYou might also like: