DESKTOP

Windows 8 : Managing Installed and Running Programs (part 2) - Managing the Command Path, Managing File Extensions and File Associations

10/13/2013 7:40:26 PM

Managing the Command Path

Windows uses the command path to locate executables. You can view the current command path for executables by using the PATH command. In a command shell, type path on a line by itself, and then press Enter. In a Windows PowerShell console, type $env:path on a line by itself, and then press Enter. In the output from either technique, observe that Windows uses a semicolon (;) to separate individual paths, marking where one file path ends and another begins.

The command path is set during logon by using system and user environment variables. The path defined in the PATH system variable sets the base path. The path defined in the PATH user variable adds to the base path by using the following syntax:

%PATH%;AdditionalPaths

Here, %PATH% tells Windows to insert the current system paths, and AdditionalPaths designates the additional user-specific paths to use.

Caution

An improperly set path can cause severe problems. You should always test any command path change before using it in a live environment. The command path is set during logon. Therefore, you must log off and then log on again to see the effects of the revised path.

Don’t forget about the search order that Windows uses. Paths are searched in order, with the last path in the PATH user variable being the last one searched. This can sometimes slow the execution of your programs and scripts. To help Windows find your programs and scripts faster, you should consider placing a required path earlier in the search order.

Be careful when setting the command path. It is easy to overwrite all path information accidentally. For example, if you don’t specify %PATH% when setting the user path, you will delete all other path information. One way to ensure that you can easily re-create the command path is to keep a copy of the command path in a file.

  • When you are working with the command prompt, you can write the current command path to a file by entering path > orig_path.txt. Keep in mind that if you are using a standard command prompt rather than an administrator command prompt, you won’t be able to write to secure system locations. In this case, you can write to a subdirectory to which you have access or to your personal profile. To write the command path to the command-shell window, type path.

  • When you are working with the PowerShell console, you can write the current command path to a file by entering $env:path > orig_path.txt. If you are using a standard console rather than an administrator console, you won’t be able to write to secure system locations. In this case, you can write to a subdirectory to which you have access or to your personal profile. To write the command path to the PowerShell window, type $env:path.

At the command prompt or in the PowerShell window, you can modify the command path by using the Setx.exe utility. You also can edit the command path by completing the following steps:

  1. In Control Panel, tap or click System And Security, and then tap or click System.

  2. In the System console, tap or click Change Settings, or tap or click Advanced System Settings in the left pane.

  3. On the Advanced tab in the System Properties dialog box, tap or click Environment Variables.

  4. Select the PATH variable in the System Variables list. Under System Variables, tap or click Edit.

  5. By default, the path value is selected. Without pressing any other key, press the Right Arrow key. This should remove the selection highlight and place the insertion point at the end of the variable value.

  6. Type a semicolon, and then enter a path to insert. Repeat this step as necessary, and then tap or click OK three times.

In Group Policy, you can use a preference item to modify the command path. Follow these steps:

  1. Open a Group Policy Object for editing in the Group Policy Management Editor. To configure preferences for computers, expand Computer Configuration\Preferences\Windows Settings, and then select Environment. To configure preferences for users, expand User Configuration\Preferences\Windows Settings, and then select Environment.

  2. Press and hold or right-click the Environment node, point to New, and then tap or click Environment Variable. This opens the New Environment Properties dialog box.

  3. In the Action list, select Update to update the path variable, or select Replace to delete and then re-create the path variable. Next, select User Variable to work with user variables.

  4. In the Name box, type Path. In the Value box, type the variable value. Typically, you’ll enter %PATH%; followed by the paths you want to add, using a semicolon to separate each path. If the affected computers have existing PATH user variable definitions, you must provide the related paths to ensure that these paths are retained.

  5. Use the options on the Common tab to control how the preference is applied. In most cases, you’ll want to create the PATH variable only once (rather than have Group Policy re-create the variable each time policy is refreshed). If so, select Apply Once And Do Not Reapply.

  6. Tap or click OK. The next time policy is refreshed, the preference item will be applied as appropriate for the Group Policy Object in which you defined the preference item.

Caution

Incorrectly setting the path can cause serious problems. Before deploying an updated path to multiple computers, you should test the configuration. One way to do this is to create a Group Policy Object in Active Directory that applies only to an isolated test computer. Next, create a preference item for this Group Policy Object, and then wait for a policy to refresh or apply policy using GPUpdate. If you are logged on to the computer, you need to log off and then log back on before you can confirm the results.

Managing File Extensions and File Associations

File extensions and file associations also are important for determining how applications run. The types of files that Windows considers to be executables are determined by the file extensions for executables. File extensions allow users to execute a command by using just the command name. File associations are what allow users to double-tap or double-click a file and open the file automatically in a related application. Two types of file extensions are used:

  • File extensions for executables Executable files are defined with the %PATHEXT% environment variable and can be set using the Environment Variables dialog box or with Group Policy preference items in much the same way as the PATH variable. You can view the current settings by typing set pathext at the command line or by typing $env:pathext at a PowerShell prompt. The default setting is PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC. With this setting, the command line knows which files are executable and which files are not, so you don’t have to specify the file extension at the command line.

  • File extensions for applications File extensions for applications are referred to as file associations. File associations are what enable you to pass arguments to executables and to open documents, worksheets, or other application files by double-tapping or double-clicking their file icons. Each known extension on a system has a file association that you can view at a command prompt by typing assoc followed by the extension, such as assoc .doc or assoc .docx. Each file association in turn specifies the file type for the file extension. This can be viewed at a command prompt by typing ftype followed by the file association, such as ftype Word.Document.8 or ftype Word.Document.12.

Note

Assoc and Ftype are internal commands for the command shell (Cmd.exe). To use the Assoc command in PowerShell, enter cmd /c assoc followed by the extension, such as cmd /c assoc .doc. To use the Ftype command in PowerShell, enter cmd /c ftype followed by the file association, such as cmd /c ftype Word.Document.8.

With executables, the order of file extensions in the %PATHEXT% variable sets the search order used by the command line on a per-directory basis. Thus, if a particular directory in the command path has multiple executables that match the command name provided, a .com file would be executed before an .exe file, and so on.

Every known file extension on a system has a corresponding file association and file type—even extensions for executables. In some cases, the file type is the extension text without the period followed by the keyword file, such as cmdfile, exefile, or batfile, and the file association specifies that the first parameter passed is the command name and that other parameters should be passed on to the application. For example, if you type assoc .exe to see the file associations for .exe executables, you then type ftype exefile. You’ll see the file association is set to the following:

exefile="%1" %*

Thus, when you run an .exe file, Windows knows that the first value is the command that you want to run and anything else provided is a parameter to pass along.

File associations and types are maintained in the Windows registry and can be set using the Assoc and Ftype commands, respectively. To create the file association at the command line, type assoc followed by the extension setting, such as assoc .pl=perlfile. To create the file type at the command line, set the file-type mapping, including how to use parameters supplied with the command name, such as ftype perlfile=C:\Perl\Bin\Perl.exe “%1” %*.

You also can associate a file type or protocol with a specific application by completing the following steps:

  1. In Control Panel, tap or click Programs. Under Default Programs, tap or click Make A File Type Always Open In A Specific Program.

  2. On the Set Associations page, current file associations are listed by file extension and the current default for that extension. To change the file association for an extension, tap or click the file extension, and then tap or click Change Program.

  3. Do one of the following:

    • In the How Do You Want To Open This Type Of File? dialog box, programs registered in the operating system as supporting files with the selected extension are listed automatically. Simply tap or click a recommended program to set it as the default for the selected extension.

    • To view other available programs, click More Options to view other programs that might also support the selected extension. Tap or click a program to set it as the default for the selected extension. Alternatively, tap or click one of the Look For An App options to locate another program to use as the default.

In Group Policy, you can use a preference item to create new file types and file associations. To create a preference item for a new file type, follow these steps:

  1. Open a Group Policy Object for editing in the Group Policy Management Editor. Expand Computer Configuration\Preferences\Control Panel Settings, and then select Folder Options.

  2. Press and hold or right-click the Folder Options node, point to New, and then tap or click File Type. This opens the New File Type Properties dialog box.

  3. In the Action list, select Create, Update, Replace, or Delete. You would use the Delete action to create a preference that removes an existing file type preference.

  4. In the File Extension box, type the extension of the file type without the period, such as pl.

  5. In the Associated Class list, select a registered class to associate with the file type.

  6. Use the options on the Common tab to control how the preference is applied. In most cases, you’ll want to create the new variable only once. If so, select Apply Once And Do Not Reapply.

  7. Tap or click OK. The next time policy is refreshed, the preference item will be applied as appropriate for the Group Policy Object in which you defined the preference item.

To create a preference item for a new file association, follow these steps:

  1. Open a Group Policy Object for editing in the Group Policy Management Editor. Expand User Configuration\Preferences\Control Panel Settings, and then select Folder Options.

  2. Press and hold or right-click the Folder Options node, point to New, and then tap or click Open With. This opens the New Open With Properties dialog box.

  3. In the Action list, select Create, Update, Replace, or Delete.

  4. In the File Extension box, type the extension of the file type without the period, such as pl.

  5. Tap or click the options button to the right of the Associated Program box, and then use the Open dialog box to select the program to associate with the file type.

  6. Optionally, select Set As Default to make the associated program the default for files with the previously specified file extension.

  7. Use the options on the Common tab to control how the preference is applied. In most cases, you’ll want to create the new variable only once. If so, select Apply Once And Do Not Reapply.

  8. Tap or click OK. The next time policy is refreshed, the preference item will be applied as appropriate for the Group Policy Object in which you defined the preference item.

Other  
  •  Windows 8 : Deploying Applications Through Group Policy, Configuring Program Compatibility
  •  Windows 8 : Installing Programs - Working with Autorun, Application Setup and Compatibility, Making Programs Available to All or Selected Users
  •  Windows 7 : Windows Management and Maintenance - Additional Tools
  •  Windows 7 : Windows Management and Maintenance - System Tools Folder in Start Menu
  •  Windows 7 : Windows Management and Maintenance - Administrative Tools
  •  Outlining AD DS Changes in Windows Server 2012 (part 3) : Auditing Changes Made to AD Objects
  •  Outlining AD DS Changes in Windows Server 2012 (part 2) : Restarting AD DS on a Domain Controller, Implementing Multiple Password Policies per Domain
  •  Outlining AD DS Changes in Windows Server 2012 (part 1) : Restoring Deleted AD DS Objects Using the Active Directory Recycle Bin
  •  Windows Server 2012 : Understanding AD DS Replication, Outlining the Role of DNS in AD DS
  •  Settings Breakdown for Windows Server 2008 and Windows Vista : Policies (part 6) - Administrative Templates
  •  
    Top 10
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    3 Tips for Maintaining Your Cell Phone Battery (part 1) - Charge Smart
    OPEL MERIVA : Making a grand entrance
    FORD MONDEO 2.0 ECOBOOST : Modern Mondeo
    BMW 650i COUPE : Sexy retooling of BMW's 6-series
    BMW 120d; M135i - Finely tuned
    PHP Tutorials : Storing Images in MySQL with PHP (part 2) - Creating the HTML, Inserting the Image into MySQL
    PHP Tutorials : Storing Images in MySQL with PHP (part 1) - Why store binary files in MySQL using PHP?
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS