IT tutorials
 
Windows
 

Windows Server 2008 Server Core : Working with Data - Working with File Associations and Types, Working with ODBC Data Sources

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/12/2012 11:24:54 AM

1. Working with File Associations and Types

Strictly speaking, you don't need to know anything about file associations or file types to work with files from the command prompt. However, Windows does need to know this information when working with files in the GUI. Whenever a user double-clicks a file, Windows looks up the file association based on the file extension, locates the file type information, and then executes an application to load the file based on what it finds. Consequently, knowing something about the file associations and types on your system is important, but it isn't something that you'll use from the command prompt.

Windows provides two commands for working with file associations and types. You use the Assoc command to determine and set the file associations. The file association connects a specific file type with an extension. The FType command defines the file type information. For example, you can specify what happens when a particular file type receives a request to open a file. The file types all rely on verbs, action words, to define specific tasks. The most common of these verbs are open and print, but depending on the file type, you might find many others.

The Assoc and the FType commands work together to show the relationships between file extensions and file types, and to allow you to modify these relationships. For example, an administrator could create a batch file to set up a user machine to use specific applications to handle certain kinds of files. The following sections describe these two commands.

1.1. Determining and Creating File Associations with the Assoc Command

The Assoc command can display or change the association between a file extension and a file type. For example, when you type Assoc .TXT and press Enter, the Assoc command responds with .TXT=txtfile on a Windows system using the default setup. This command uses the following syntax:

ASSOC [.ext[=[fileType]]]

The following list describes each of the command line arguments.


.ext

Specifies the file extension that you want to assign or display. The file extension must begin with a period or the utility will fail. For example, you must type .TXT instead of TXT alone.


fileType

Specifies the file type to assign to the file extension. The file type must exist within the registry (create it if necessary using the FType command). Always place an equals sign between the file extension and type. For example, to associate the .TXT extension with the txtfile type, you'd type Assoc .TXT=txtfile and press Enter at the command line.

1.2. Determining and Creating File Types with the FType Command

The FType command can display the open verb action or set the action for this verb for any file type on your system. You can also use it to create new file types as needed to express a specific file requirement. The FType command only works with the open verb, not any of the other verbs (such as print) that the file type might contain. Even so, this command is invaluable in setting up a system quickly.

A file type always includes the file type name and the associated action. For example, if you type FType txtfile at the command prompt and press Enter, the FType command responds with txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1 on a system using the default setup. In this case, txtfile is the file type. The action appears after the equals sign. The %SystemRoot% environment variable points to the Windows directory on your machine. The System32 directory contains many of the executable files including both EXEs and DLLs. The application that Windows starts to load is a text file in Notepad. The %1 after Notepad is a placeholder for the file. You can include as many placeholders as required by the application. The action can also include any command line switches that the application requires to handle the file type. This command uses the following syntax:

FTYPE [fileType[=[openCommandString]]]

The following list describes each of the command line arguments.


fileType

Specifies the name of the file type to display or change. Many common file types use the file extension followed by the word file as a name. For example, Windows normally associates a file with a .TXT extension with the txtfile file type.


openCommandString

Defines the action to take when a user double-clicks a file or otherwise requests that Windows open it. The action must include the application location and application name (including file extension). You may optionally include command line arguments, placeholders, and other application input as needed.

2. Working with ODBC Data Sources

Many people see Open Database Connectivity (ODBC) as old hat—technology that has gone the way of the dinosaur. However, this technology is still alive and well for many applications because it's so universal. You'll find that there are many more ODBC database drivers than any other type for Windows systems. Consequently, even though this technology is outdated, many developers still use it because ODBC is very reliable, available on just about any Windows system, and well understood. The following sections describe two ODBC command line topics.

NOTE

This discussion shows how to configure ODBC sources at the command line. It doesn't demonstrate how to create database applications based on those sources, nor does it tell you how to create a data source for a specific vendor product. Refer to a programming manual for your language of choice to discover how to work with ODBC data sources in an application. Your database product manual should contain information about how to configure the database for use with ODBC.

2.1. Configuring the ODBC Environment with the ODBCConf Utility

The ODBCConf utility helps you configure ODBC at the command line, rather than using the ODBC Data Source Administrator utility available in the Administrative Tools folder of the Control Panel—listed as the Data Sources (ODBC) console. You can use this utility to configure new data sources, check data source status, and perform other tasks on a remote machine from the command line. This utility uses the following syntax:

ODBCConf [/S] [/C] [/R] [/F Filename] [/E] [/L{n | v | d} Filename] [/A {Action}]

					  

The following list describes each of the command line arguments.


/S

Prevents ODBCConf from displaying any error messages. Normally, it's a better idea to redirect the error message output to an error log when working with a remote system so that you can determine whether the actions succeeded.


/C

Forces ODBCConf to continue executing actions even if an action fails. This command line switch works well in situations where you need to perform multiple independent actions.


/R

Performs the requested actions after a system reboot.


/F
Filename

Performs actions based on an input file. The response file contains a list of actions and all of the required input information. This option is often the best solution when you plan to perform a configuration on multiple machines or multiple times on the same machine.


/E

Erase the response file when the action completes. Use this command line switch with the /F switch.


/L{n | v | d}
Filename

Sets the ODBCConf utility to output a log. You must provide a logging mode of (n)ormal, (v)erbose, or (d)ebug, along with a filename for the log. For example, /Lv MyLog.LOG would output a log in verbose mode to the MyLog.LOG file. The normal mode outputs the least information, while the debug mode outputs the most information. Using debug mode consumes considerable disk space and slows execution of any actions. You must use this command line switch to see any changes that ODBCConf makes since the utility doesn't display successful actions.


/A
{Action}

Defines one or more actions to perform. The action must appear within curly brackets ({}).

The ODBCConf utility requires some type of action input to perform any task. You can provide a list of actions directly on the command line or you can use a response file. When working at the command line, you can include multiple /A command line switch entries. The ODBCConf utility executes these switches in order, so you must create the command line to reflect the required order. For example, you can't register a new Microsoft Data Access Components (MDAC) version until after you register its accompanying server. The following list describes each of the documented actions for the ODBCConf utility (some people have reported undocumented actions that I wasn't able to confirm).


REGMDACVERSION
Version

Registers a new version of the MDAC as specified by the Version argument. Normally, Microsoft performs this task for you as part of installing the new MDAC on your machine.


SETFILEDSNDIR

Changes the File DSN directory to the specified value. The default setting is the \Program Files\Common Files\ODBC\Data Sources directory.

Whenever you work with directory names that contain spaces, always enclose the directory name in double quotes. For example, to change the File DSN directory, you might type ODBCConf /lv ODBCConf.log /a {SETFILEDSNDIR "F:\Program Files\Common Files\ODBC\ Data Sources"}. Notice that the directory name is enclosed in double quotes so that the command line utility treats it as a single entity.



INSTALLDRVRMGR

Installs a new driver manager.


INSTALLDRIVER
Configuration Path

Installs a new ODBC driver. The configuration argument is the configuration name, which you modify using the CONFIGDRIVER action. You must obtain this information from the database vendor. In fact, some vendors, such as Oracle, do provide files with all of the required information provided. The path is the location of the new driver.


INSTALLTRANSLATOR
Configuration Path

Installs a new code page translator. The configuration argument is a name that you use to reference the code page translator configuration. Modify the configuration using the CONFIGDRIVER action. You must obtain the configuration data from the database vendor. The path is the location of the new driver.


CONFIGDRIVER
Name Parameters

Configures a driver for use. The name argument is the name of the driver configuration supplied as part of an INSTALLDRIVER or INSTALLTRANSLATOR action. The parameters argument contains name value pairs that define the configuration for the driver. The name is followed by an equals sign, which is followed by the argument. You can use this action to configure an existing driver on the user's machine as long as you know the driver configuration name.


CONFIGDSN
Name {DSN | Attributes}

Creates a new user DSN entry that's accessible only by the current user. The name is the name of the driver supplied during installation. The DSN is the name of the DSN as it will appear in the ODBC Data Source Administrator utility. The attributes describe the information required to make the database connection. For example, a SQL Server DSN might include these arguments: "SQL Server" "DSN=Northwind|Server=(Local)|Description=SQL Server|Database=Northwind||". In this case, the DSN uses the SQL Server configuration. The action creates a DSN named Northwind that uses the (Local) instance of SQL Server and the Northwind database.


CONFIGSYSDSN
Name {DSN | Attributes}

Creates a new system DSN entry that's accessible by everyone on a particular machine. In all other ways, this action works like the CONFIGDSN action.


REGSVR
Path

Registers a new MDAC server on the machine. The path argument specifies the location of the server DLL. You normally combine this action with the REGMDACVERSION action to register a new MDAC server.

2.2. Creating an ODBC Data Source at the Command Line

More than a few people have experienced problems using the ODBCConf utility because it often requires use of complex command line syntax. However, there's an easier way of adding an ODBC data source to a remote machine. Simply add the data source using a file DSN. These DSN files normally appear in the \Program Files\Common Files\ODBC\Data Sources folder of the remote system. Adding a DSN file automatically adds the DSN to the remote machine. (The application must take the file DSN into account or adding the DSN using this technique might not work.)

Although every database uses a different configuration strategy, the file DSN is always a text file with a DSN extension. It's essentially a form of INI (initialization or configuration) file. Here's an example file DSN for an Access database.

[ODBC]
DRIVER=Microsoft Access Driver (*.mdb)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=2048
FIL=MS Access
DriverId=25
DefaultDir=G:\Access
DBQ=G:\Access\db1.mdb

Notice that this DSN includes such information as the database driver and the user identifier. It also includes the location of the Access database and other information to control access to it. You can easily create such a file using the ODBC Data Source Administrator utility, make any required changes to the text file for the remote system, and then copy it to the remote system's file DSN directory.

 
Others
 
- Windows Server 2008 Server Core : Working with Data - Performing Bulk File Transfers with the XCopy Utility
- Windows Server 2008 Server Core : Working with Data - Validating File Operations with the Verify Command, Performing Backups with the WBAdmin Utility
- Windows Small Business Server 2011 : Partitions and Volumes (part 4) - RAID-5 Volumes, Mounting a Virtual Hard Disk, Mounting a Volume
- Windows Small Business Server 2011 : Partitions and Volumes (part 3) - Adding a Mirror, Drive Failure in a Mirrored Volume
- Windows Small Business Server 2011 : Partitions and Volumes (part 2) - Extending or Shrinking a Volume
- Windows Small Business Server 2011 : Partitions and Volumes (part 1) - Adding a Partition or Volume
- Windows Small Business Server 2011 : Disk Management - Managing Disks
- Supporting Computers Running Windows 8 (part 2) - Getting Advanced System Information, Working with WMI Control
- Supporting Computers Running Windows 8 (part 1) - Working with the Computer Management Console, Getting Basic System and Performance Information
- Windows 7 Networking : Libraries and Public Folders, Network and Sharing Options
 
 
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