473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Automatically open file with - executable with same name

jkmyoung
2,057 Expert 2GB
I am attempting to automatically open .xml files with a .bat script when I open them.

Microsoft XP 2002 SP 2

Ultimate goals:
1. Figure out how Open With list is stored.
2. Edit Open With list to clear old entries, and add new entries.

Current:
When I double click on xml files, they are automatically run with
C:\project1\Preprocess.bat

Wanted:
When I double click on xml files, they are automatically run with
C:\project2\Preprocess.bat

Attempts to change:
1. a. Right clicked on xml file and selected Open With... Choose Program
b. Browsed to C:\project2\Preprocess.bat
c. selected Preprocess.bat
d. selected "always open with this file."

Result: when the file executes, or when I later double click on the file, it runs with C:\project1\Preprocess.bat. The file listing in the screen of programs to select from has not updated.


2. a. Renamed C:\project1\Preprocess.bat to C:\project1\Preprocess2.bat
b. Right clicked on xml file and selected Open With... Choose Program
c. Preprocess.bat can not be found.
d. Browsed to C:\project2\Preprocess.bat
e. Preprocess.bat still can not be found.

The only thing that works is renaming my current C:\project2\Preprocess.bat.
However, I don't want to have to version up my .bat files for every version of every project. Why does windows not update these entries??
Mar 25 '09 #1
1 5495
Nilpo
2
As you probably well imagined, these settings are held in the registry. Specifically, file type handlers are housed in the HKEY_CLASSES_ROOT hive. If you navigate this hive in the Registry Editor, you'll notice a key dedicated to each registered file type on your system. So your .xml settings will be housed here:

HKEY_CLASSES_ROOT\.xml

This key is used to register the file type and its handler along with any other pertinent information about that file type. In this case, XML files are already recognized by Windows so this key should already be populated for you. It's default string value assigns its handler (xmlfile) and its Content Type string value assigns the default content type (text/xml). We're only concerned with the first at this point.

As you continue navigating down the HKCR hive, you will find the handler entries. This is where you'll make your changes. The xmlfile handler is located at the following key:

HKEY_CLASSES_ROOT\xmlfile

This is the key that performs the magic. It houses all of the default actions for this file type. We're working with its default Open command so we can drill down a bit further into this key and edit its shell actions.

HKEY_CLASSES_ROOT\xmlfile\shell\open

This key defines the shell open settings. Its default string value can be set to change the open text on the context menu in Windows Explorer. Leaving this value unset will display the default "Open" text when you right-click an XML file. Beneath the open key there is a command key that we need to edit.

HKEY_CLASSES_ROOT\xmlfile\shell\open\command

This key's default string value assigns the command line that should be executed whenever this file type is opened through the Windows Shell (i.e. by being double-clicked). Your command line should look like this:

C:\project2\Preprocess.bat "%1"

The %1 reference is used to pass the path and file name of the file being opened as an argument to the batch file. I've surrounded this in quotes in case the XML file name or path contains any spaces. Setting this value will make the changes you wish to make.

Here's what the same thing looks like as a .reg file.
Expand|Select|Wrap|Line Numbers
  1. Windows Registry Editor Version 5.00
  2.  
  3. [HKEY_CLASSES_ROOT\xmlfile\shell\open]
  4.  
  5. [HKEY_CLASSES_ROOT\xmlfile\shell\open\command]
  6. @="C:\\project2\\Preprocess.bat \"%1\""
You can also work with File Types through the Window GUI. In either My Computer or Windows Explorer, choose Folder Options... from the Tools menu to open the Folder Options dialog. You may add or edit registered file types on the File Types tab.

Nilpo

<links removed>
Mar 29 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Matt | last post by:
I want to write a ASP page to open/download a file In fileview.jsp, I have the file browse, and when user click submit button, fileview2.asp should open the file. fileview.asp ============...
7
by: A_StClaire_ | last post by:
hi, I'm working on a project spanning five .cpp files. each file was used to define a class. the first has my Main and an #include for each of the other files. problem is my third file...
4
by: Frank | last post by:
Could someone tell me how to open a file at run time that I didn't know the name of at compile time? I know how to open a file at compile time when I know what the name is going to be. FILE...
6
by: Kevin Frevert | last post by:
In the process of learning VS2005/C# (having a background in Borland Delphi 2 through 2005) I came across an interesting feature of Visual Studio's file management. At first, it appeared there...
8
by: Seth Darr | last post by:
I'm working on migrating an Classic ASP/VB6 COM application from an NT Server with IIS<6 to an virtual machine running Windows Server 2003 and IIS 6. I've worked through most of the obvious...
1
by: Nico Grubert | last post by:
Dear Python developers, I use a short python script in order to run an external application plus to open a browser displaying a default page. My Setup: Python 2.4.3. / Windows2000 #...
28
by: Tim Daneliuk | last post by:
I have a program wherein I want one behavior when a file is set as executable and a different behavior if it is not. Is there a simple way to determine whether a given named file is executable...
6
by: Roger | last post by:
if I make a copy of northwind.mdb sample and import data till it reaches 350Gb in size and then I make a second copy of northwind then I open nw1.mdb and do a compact / repair that takes 30-60...
25
by: Andy_Khosravi | last post by:
I just recently changed my database that I'm running from a monolithic DB to a split FE/BE. The front end resides on the client machine and the BE resides on a network drive. I'm experimenting with...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.