Windows 7 / Getting Started

Managing Environment Variables with the SetX Utility

The SetX utility performs essentially the same tasks as the Set command described in the "Managing Environment Variables with the Set Command" section of the tutorial. However, it offers considerably more flexibility because you can use SetX over a network to interact with variables on other machines. In addition, it offers considerable flexibility in setting variables, such as letting you choose between the current user and the system as a whole. Rather than repeat all of the common information for using SetX, please refer to the Set command as a starting point. This command uses the following syntax:

SETX [/S system [/U [domain\]user [/P [password]]]] var value [/M]
SETX [/S system [/U [domain\]user [/P [password]]]] var /K regpath [/M]
SETX [/S system [/U [domain\]user [/P [password]]]] /F file {var
  {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]

The following list describes each of the command line arguments.

/S system Specifies the remote system that you want to check. In most cases, you'll also need to supply the /U and the /P command line switches when using this switch.

/U [domain\]user Specifies the username on the remote system. This name may not match the username on the local system. You'll need to supply a domain name when working with a domain controller.

/P [password] Specifies the password for the given user. You can provide the command line switch without specifying the password on the command line in cleartext. The system prompts you for the password. Using this feature can help you maintain the security of passwords used on your system.

var Contains the name of the variable you wish to change.

value Sets the specified variable to the supplied value. You don't have to provide the equals sign (=) as you do when working with the Set command. Place values with spaces within double quotes.

/M Sets the value as a system-wide (machine-level) variable that appears in HKEY_LOCAL_MACHINE. The default setting places the variable within the current user's environment.

/K regpath Sets the specified variable using the content of a registry key. You must provide the fully qualified registry value (including all of the keys), such as KEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName.

/F file Specifies the name of a text file to use for settings. You must also provide the position of the setting within the file as an absolute or relative coordinate (line number and character position). In addition, if the setting is delimited, you must provide the delimiter used for it.

/A x,y Provides the absolute position of the setting within the file. You must provide the position as a line number and character number.

/R x,y string Provides a relative position of the setting within the file. SetX first searches for the string you specify within the file. It then moves relative to that string the number of lines and characters within the line that you specify.

/X Displays the file contents using x and y coordinates. This argument doesn't actually set any variables. What it does is display the position of each potential setting within the file so that you can use the /A and /R arguments with greater ease.

/D delimiters Defines the delimiters used to begin and end settings entries within the file. The default settings include space, tab, carriage return, and linefeed. You can use any ASCII character as a delimiter. The maximum number of delimiters, including the default delimiters, is 15.

Executing Applications Using the Start Command

A common way to handle this problem, when the application supports it, is to ask it to return immediately and continue working in the background. The only problem with this approach is that you aren't sure that the command or utility completed successfully. The Start command helps you overcome this problem by creating a new window for the command or window to run in. The command or utility still controls the command prompt until it completes, but since it runs in another window, the user can continue working.

Another use for this utility is to start the command or utility in a window with a specific title. You can apply settings to a window that rely on the window title. Whenever you open a window with that title, it also has the special formatting that you specified. In short, you can create custom environments in which to run a utility. This utility uses the following syntax:

START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED] 
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL 
      | /BELOWNORMAL] [/WAIT]
    [/B] [{command | program}] [parameters]

The following list describes each of the command line arguments.

"title" Defines the title of the command window title bar.

/DPath Specifies the starting directory for the command window. This value doesn't have to be the same as the path for the command that you want to execute. For example, it might be the path to the data directory for the command.

/B Starts the application without creating a new window. The application executes as a background task and doesn't display a user interface. The lack of user interface means that the application won't provide Ctrl+C handling, so you would need to stop the application using the Task Manager or an application such as the TaskKill command. Some applications may also allow termination using Ctrl+Break.

/I Passes the standard command environment to the new window, rather than using any changes made to the command environment by the current command window. Using this command line switch ensures that the application won't run in a contaminated environment where an environmental setting could adversely affect the way the application runs.

/MIN Starts the application with the command window minimized.

/MAX Starts the application with the command window maximized.

/SEPARATE Starts 16-bit Windows applications in a separate memory space. Normally, Windows uses a separate memory space for all 32-bit applications, but a single memory space for all 16-bit applications. Older applications don't always use memory correctly, resulting in memory corruption that can cause other applications to fail. Using this command line switch eliminates shared memory corruption problems. However, this feature comes at the cost of performance and overall system resource usage. Unlike 32-bit memory spaces, 16-bit memory spaces remain fixed in memory, which uses the memory inefficiently and causes memory fragmentation. Memory fragmentation can cause Windows to perform inefficiently, leading to performance problems. In short, use this command line switch only when you actually experience problems.

/SHARED Starts the 16-bit Windows application in a shared memory space. This is the default setting and you should normally use it unless you experience memory corruption problems while running the application.

/LOW Starts the application in the IDLE priority class. Use this priority setting for applications that only run when other applications don't require the processor. This command line switch helps the system function more efficiently when you want to run the application as a background task and don't care when it completes its work.

/BELOWNORMAL Starts the application in the BELOWNORMAL priority class. Use this priority setting for background applications that you want to complete in a timely manner, but not at the expense of foreground applications.

/NORMAL Starts the application in the NORMAL priority class. This is the default setting. Foreground applications normally start at this priority. You should only use this setting for applications that you want to complete at a normal pace. This setting does affect all foreground application responsiveness.

/ABOVENORMAL Starts the application in the ABOVENORMAL priority class. This setting places the application at a slightly higher priority than standard applications. The other foreground tasks continue to run, but at a noticeably slower pace. Use this setting for priority applications that must complete tasks quickly.

/HIGH Starts the application in the HIGH priority class. You won't normally have a good reason to use this priority for any application. Using this priority level can affect system functionality and definitely slows other foreground applications to a crawl. Always use this setting with extreme caution.

/REALTIME Starts the application in the REALTIME priority class. Using this priority level stops execution of other foreground tasks and some system tasks as well. In addition, system functionality degrades noticeably. In some circumstances, the system could actually freeze and require a reboot. Generally, you don't want to use this priority for any reason.

/WAIT Starts the application and waits for it to terminate. This setting ensures that you know when an application completes its task.

{command | program} Specifies the internal command/batch file or the external utility/ application to run. The command window remains visible after you run an internal command or batch file because the system executes the command processor (CMD.EXE) with the /K switch. (See the "Using the CMD Switches" section of this tutorial for details on the CMD.EXE command line switches.) The system runs external utilities and applications in a window or in a full-screen console. Unless you change the default behavior using a command line switch, the window or full-screen console closes when the application completes execution.

parameters Specifies the parameters (arguments) passed to the command or program.

Determining the Operating System Version with the Ver Command

The Ver command is one of the easier commands to use. It doesn't require any arguments and provides only one type of output. Whenever you use the Ver command, you receive the operating system version information. The version information contains the operating system name in human-readable form, the major version number, the minor version number, and the build number. For example, the current Windows XP version at the time of this writing is Microsoft Windows XP [Version 5.1.2600]. Server Core displays something like Microsoft Windows [Version 6.0.6001].

Getting Volume Information with the Vol Command

The Vol command displays the volume information for the current or selected drive. The information includes the drive letter, the drive volume name, and the serial number. This command uses the following syntax:

VOL [drive:]

The following describes the command line argument.

drive Specifies the letter of the drive for which you want to obtain volume information. The default is the current drive.

[Previous] [Contents] [Next]