IT tutorials
 
Windows
 

Windows Server 2008 : Basic Rules When Using the Command Prompt - Understanding Variables, Understanding Switches

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
5/2/2013 1:38:46 AM

1. Understanding Variables

A variable is simply a placeholder for an actual value. You don’t have to know the actual value as long as you know the placeholder. For example, the location of the Windows Server 2008 operating system folder is usually c:\Windows, but it can be on another drive and even have a different name. However, the %systemroot% variable always points to the actual location of the operating system folder.

For example, if you want to see the path to the sysvol folder, you can use this command:

echo %systemroot%\sysvol

Tip

Variables always start and end with a percent symbol (%). You can easily see the value of any variable by using the echo command followed by the variable.


Some of the commonly referenced variables are shown in the following table.

VariableDescription
%systemroot%
%windir%

Shows the path to the Windows folder (typically C:\Windows).
%programfiles%Shows the path to the Program Files folder (typically C:\Program Files).
%systemdrive%Returns the drive of the root directory (typically C:\).
%appdata%Returns the location where applications store data by default.
%userdomain%Gives the name of the domain that contains the currently logged-on user’s account.
%logonserver%Lists the name of the domain controller that validated the current logon session (when the system is joined to a domain).
%processor_architecture%Returns the architecture of the processor (such as x856 for 32-bit or AMD64 for 64-bit processors).
%userprofile%Lists the location of the profile for the current user.
%allusersprofile%Lists the location of the All Users Profile.
%cd%Lists the current directory string.
%date%Returns the current date.
%time%Returns the current time.
%errorlevel%Gives the error number of the last executed command. Anything other than 0 indicates an error occurred.

Tip

You can use variables in commands at the command prompt. For example, if you want to open the Windows update log (windowsupdate.log), you can use the following command:

notepad %systemroot%\windowsupdate.log


Tip

You can view a listing of all variables with the set command.


It’s also possible to create your own variables. This can sometimes be useful in scripts.

VariableDescription
set variable-name = value
C:\>set myvariable = test

Creates the variable and assigns a value.
C:\>echo %myvariable%
Test

Shows the value of the variable.

2. Understanding Switches

You can modify most commands by using one or more switches. A switch is preceded by a space and a forward slash (/) or a space and a dash (-). For example, if you want to flush the DNS cache, you use the ipconfig command and modify it with the /flushdns switch like this:

ipconfig /flushdns

Some commands can use either a forward slash or a dash, whereas others work only with one or the other.

CommandDescription
C:\>ipconfig -flushdns
C:\>ipconfig /flushdns

Both of these commands work the same.
C:\>ipconfig/flushdns

This works. Even though the space is omitted before the slash, the ipconfig command recognizes it.
C:\>ipconfig-flushdns

ipconfig-flushdns
is not recognized as an internal or external command, operable program, or batch file.
This fails. The ipconfig command doesn’t recognize the dash (-) as a switch without a space.

Tip

It’s best to always use a space before the switch because this consistently works. Some commands do not work if you use the forward slash (/) or dash (-) without a space preceding it.

 
Others
 
- Windows Server 2008 : Basic Rules When Using the Command Prompt - Using Uppercase or Lowercase, Using Quotes
- Windows 8 : Settings and Customization - Policies
- Windows 8 : Settings and Customization - The Registry
- Using Windows Home Server’s Command-Line Tools : Working at the Command Line
- Using Windows Home Server’s Command-Line Tools : Getting to the Command Line
- Windows Vista : Desktop Searching with the Windows Search Engine
- Windows Vista : Metadata and the Windows Explorer Property System
- Windows 7 : Email and Newsgroups with Windows Live Mail - Creating and Sending New Mail
- Windows 7 : Email and Newsgroups with Windows Live Mail - Windows Live Mail Quick Tour
- Monitoring Windows Small Business Server 2011 : Configuring the Backup Service (part 2) - Windows Server Backup Using Native Tools
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us