DOS Program to Change File Associations

J

James Reid

I'm looking for the source code for a DOS command line c/c++ program
that can change file associations. In other words it can cause any
version of Windows to associate a particular .exe file with a
particular file name extension.

It would be preferable if the source code would work with Borland's
free DOS command line C/C++ compiler.
 
D

David Wade

James Reid said:
I'm looking for the source code for a DOS command line c/c++ program
that can change file associations. In other words it can cause any
version of Windows to associate a particular .exe file with a
particular file name extension.

It would be preferable if the source code would work with Borland's
free DOS command line C/C++ compiler.

1) This is a system specific request this group only deals with questions
about "standard" C....

<Pedant Mode On>
2. As a DOS program cannot by definition know any thing about Windows System
calls what you ask is, strictly speaking impossible. You can build what I
think is called a "Command Window .exe", which looks a bit like a DOS
program to the casual user, but which is really a Windows program that runs
in a cmd window.....

Whats wrong with using the currently free "Visual Studtio Express"?

Dave.
 
J

James Reid

David said:
2. As a DOS program cannot by definition know any thing about Windows System
calls what you ask is, strictly speaking impossible.

You can build what I
think is called a "Command Window .exe", which looks a bit like a DOS
program to the casual user, but which is really a Windows program that runs
in a cmd window.....

Yes. That's probably what the "assoc" program is. "assoc" is a program
which comes with Windows XP. It's a command line program, and one of
the things that it does is to allow file associations to be changed.

But what I want is the source code for such a program so that I can
have it assign a specific file name extension with a specific program,
and so that it works with all versions of Windows.
Whats wrong with using the currently free "Visual Studtio Express"?

Oh. I didn't know about that. I'll check it out. Thanks, David.

James
 
K

Keith Thompson

James Reid said:
Yes. That's probably what the "assoc" program is. "assoc" is a program
which comes with Windows XP. It's a command line program, and one of
the things that it does is to allow file associations to be changed.

But what I want is the source code for such a program so that I can
have it assign a specific file name extension with a specific program,
and so that it works with all versions of Windows.

And you are asking in the wrong place. Standard C cannot do what
you're trying to do without system-specific extensions. Try a Windows
newsgroup.
 
J

James Reid

Keith said:
And you are asking in the wrong place. Standard C cannot do what
you're trying to do without system-specific extensions. Try a Windows
newsgroup.

Isn't it simply a matter of making changes to the registry? Any
programming language should be able to do that.
 
J

James Reid

Keith said:
And you are asking in the wrong place. Standard C cannot do what
you're trying to do without system-specific extensions. Try a Windows
newsgroup.

Isn't it simply a matter of making changes to the registry? Any
programming language should be able to do that.
 
R

Richard Heathfield

James Reid said:
Isn't it simply a matter of making changes to the registry? Any
programming language should be able to do that.

Show me. Show me how Fortran 77 can make changes to the registry. Or ISO
Basic. Or Algol-68. Are those languages too old for you? Okay, let's see
you do it in Ook!, or Whitespace, or Princess.
 
J

James Reid

Richard said:
Show me. Show me how Fortran 77 can make changes to the registry. Or ISO
Basic. Or Algol-68. Are those languages too old for you? Okay, let's see
you do it in Ook!, or Whitespace, or Princess.

The Windows "Registry" means binary files. Even GWBASIC can change
binary files! What's the problem?
 
R

Richard Heathfield

James Reid said:
The Windows "Registry" means binary files. Even GWBASIC can change
binary files! What's the problem?

Pretend I'm from Missouri. You gots to show me.
 
K

Keith Thompson

James Reid said:
Isn't it simply a matter of making changes to the registry? Any
programming language should be able to do that.

Standard C, which is what we discuss here, has absolutely no concept
of a "registry".

I'm sure it's possible to make changes to the registry using some
system-specific extensions. We don't discuss system-specific
extensions here.

Try a Windows newsgroup. You're likely to get an answer in
comp.os.ms-windows.programmer.win32. You're not likely to get an
answer in comp.lang.c (and if you do, nobody else here is going to be
able to find any bugs in it).

You've been told several times that this isn't the right place for
your question. Why don't you believe us?
 
K

Keith Thompson

James Reid said:
The Windows "Registry" means binary files. Even GWBASIC can change
binary files! What's the problem?

<OT>
Presumably the operating system provides an interface that deals with
the registry. Attempting to treat it as binary files sounds extremely
dangerous, and subject to random failure in different versions of the
operating system.

Use the OS-provided interface. Ask about it in a newsgroup where it's
topical.
</OT>
 
M

Mark McIntyre

Isn't it simply a matter of making changes to the registry?

What registry?
Any programming language should be able to do that.

Only using system specific extensions. Really, you need to ask in a
Windows newsgroup.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
M

Mark McIntyre

The Windows "Registry" means binary files. Even GWBASIC can change
binary files! What's the problem?

Sure, you can change it with C. All you need to do is

a) discover the binary format of the registry
b) discover how to bypass security so you can see the bits you need
c) fopen the registry file (lets pretend its an ordinary file)
d) fseek to the right place, somehow
e) change some bits in it. Note that in-place file editing is in
general impossible in Standard C. And you can't use the usual trick of
copying the file to a new one since the file is locked open by the OS.
f) close the file and hope like hell you didn't fsck your registry.
g) reboot the PC and pray.
h) reinstall Windows and curse.

Or alternatively you could go to a windows group and ask how to use
the registry editing functions in the Win32 API.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
M

Mark McIntyre

Isn't it simply a matter of making changes to the registry? Any
programming language should be able to do that.

Sure. However you need to make specific changes which have meaning and
don't toast the rest of the file.

Would you modify a database by opening it as a plain binary file, and
hacking around in it, or would you use the API designed specially to
access the data? Would you edit a sound file by opening it as plain
binary and flipping bits, or would you use a sound editing API?

And if you're asking "how do I write an API to modify the Windows
registry", you DEFINITELY need to go to a windows group.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top