C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28691
Number of posts: 94711

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to change a file extension. Posted by Digga on 2 Jul 2005 at 2:12 PM
I want to know if I can change a file extension of a program. Instead of the program saying .exe I want it to say something else. Now I know that I can change the file etension through DOS, but it causes the program to not work. I want the program to work and have a different extension. Is this is possible could anyone show me how its done.

--Digga

Report
Re: How to change a file extension. Posted by IDK on 2 Jul 2005 at 2:15 PM
: I want to know if I can change a file extension of a program. Instead of the program saying .exe I want it to say something else. Now I know that I can change the file etension through DOS, but it causes the program to not work. I want the program to work and have a different extension. Is this is possible could anyone show me how its done.
:
: --Digga
:
:
As I know it's not possible.

If you change the extension to .com or
some other executable exctension and
convert the file to the propper format
it should work.

Niklas Ulvinge aka IDK

Report
Re: How to change a file extension. Posted by stober on 2 Jul 2005 at 2:25 PM
This message was edited by stober at 2005-7-2 16:33:14

: : I want to know if I can change a file extension of a program. Instead of the program saying .exe I want it to say something else. Now I know that I can change the file etension through DOS, but it causes the program to not work. I want the program to work and have a different extension. Is this is possible could anyone show me how its done.
: :
: : --Digga
: :
: :
: As I know it's not possible.
:
: If you change the extension to .com or
: some other executable exctension and
: convert the file to the propper format
: it should work.
:
: Niklas Ulvinge aka IDK
:
:


You can name it any extension you want. If the file does not have one of the standard extensions you have to speify the extension when you want to execute the program. Its not necessary to change the file format.


executing the program doesn't seem to work with CreateProcess() win32 api function. But the system() function works as well as executing it directly from a command prompt.

Report
How do you do that. Posted by Digga on 2 Jul 2005 at 2:44 PM
So how do I change the file extension to whatever I want without changing the format of the file?
Report
Re: How do you do that. Posted by stober on 2 Jul 2005 at 3:52 PM
This message was edited by stober at 2005-7-2 15:55:32

: So how do I change the file extension to whatever I want without changing the format of the file?
:

just rename it. There are several ways to do that.
1. use Windows explorer to rename the file

2. use MS-DOS proompt
c:>ren myfile.exe myfile.aaa <Enter>


3. to do that with c program
rename("myfile.exe","myfile.aaa");



There are several other ways too.
Report
No Go Posted by Digga on 2 Jul 2005 at 6:16 PM
I can get it to rename the program extension but it does not allow the program to run. If you give it a common extension like .doc or .txt it runs it as a word document or text file. I'm renaming the program extensiom to another name. Which works. but the program does not run and the icon changes. So is this something that can be programmed in or is this impossiable because windows does not like it when people fool around with extension.

Digga
Report
Re: No Go Posted by stober on 2 Jul 2005 at 7:53 PM
: I can get it to rename the program extension but it does not allow the program to run. If you give it a common extension like .doc or .txt it runs it as a word document or text file. I'm renaming the program extensiom to another name. Which works. but the program does not run and the icon changes. So is this something that can be programmed in or is this impossiable because windows does not like it when people fool around with extension.
:
: Digga
:

my previous post told you how to do it. in c program use system() function, or execute it manually from the command-line. I was not able to execute it by using windows explorer.
Report
Re: How to change a file extension. Posted by shaolin007 on 2 Jul 2005 at 8:15 PM
: I want to know if I can change a file extension of a program. Instead of the program saying .exe I want it to say something else. Now I know that I can change the file etension through DOS, but it causes the program to not work. I want the program to work and have a different extension. Is this is possible could anyone show me how its done.
:
: --Digga
:
:

Your OS uses the file extension to determine how and where to read the PSP header in your executable. If you rename the file then the OS will assume that it is not an executable and not run it.



Report
Re: How to change a file extension. Posted by stober on 2 Jul 2005 at 8:19 PM
: : I want to know if I can change a file extension of a program. Instead of the program saying .exe I want it to say something else. Now I know that I can change the file etension through DOS, but it causes the program to not work. I want the program to work and have a different extension. Is this is possible could anyone show me how its done.
: :
: : --Digga
: :
: :
:
: Your OS uses the file extension to determine how and where to read the PSP header in your executable. If you rename the file then the OS will assume that it is not an executable and not run it.
:

:

maybe. please read my previous posts.
:

Report
Re: How to change a file extension. Posted by shaolin007 on 2 Jul 2005 at 8:30 PM
: : : I want to know if I can change a file extension of a program. Instead of the program saying .exe I want it to say something else. Now I know that I can change the file etension through DOS, but it causes the program to not work. I want the program to work and have a different extension. Is this is possible could anyone show me how its done.
: : :
: : : --Digga
: : :
: : :
: :
: : Your OS uses the file extension to determine how and where to read the PSP header in your executable. If you rename the file then the OS will assume that it is not an executable and not run it.
: :

: :
:
: maybe. please read my previous posts.
: :
:
:

I know you can rename a file but to execute it with the new file extension should fail since the PSP isn't being translated by the OS. If the OS doesn't know what kind of executable it is from some of the basic types like PE, MZ, COM, ect. then how would it know how to read the PSP? Is there a function in the Winapi that could execute the code by calling the renamed program? I would be curious to know of such.



Report
Re: How to change a file extension. Posted by stober on 2 Jul 2005 at 9:45 PM
:
: I know you can rename a file but to execute it with the new file extension should fail since the PSP isn't being translated by the OS. If the OS doesn't know what kind of executable it is from some of the basic types like PE, MZ, COM, ect. then how would it know how to read the PSP? Is there a function in the Winapi that could execute the code by calling the renamed program? I would be curious to know of such.
:

:

try it yourself as I described twice before. rename myprog.exe to myprog.aaa (or some other nonsense extension) and execute it form a command prompt. It doesn't work from Windows explorer, as I also said twice before.
Report
Re: How to change a file extension. Posted by shaolin007 on 3 Jul 2005 at 5:12 AM
This message was edited by shaolin007 at 2005-7-3 5:33:26

: :
: : I know you can rename a file but to execute it with the new file extension should fail since the PSP isn't being translated by the OS. If the OS doesn't know what kind of executable it is from some of the basic types like PE, MZ, COM, ect. then how would it know how to read the PSP? Is there a function in the Winapi that could execute the code by calling the renamed program? I would be curious to know of such.
: :

: :
:
: try it yourself as I described twice before. rename myprog.exe to myprog.aaa (or some other nonsense extension) and execute it form a command prompt. It doesn't work from Windows explorer, as I also said twice before.
:


Ok lets drop it.




Report
Re: How to change a file extension. Posted by DB1 on 2 Jul 2005 at 9:46 PM
: : : : I want to know if I can change a file extension of a program. Instead of the program saying .exe I want it to say something else. Now I know that I can change the file etension through DOS, but it causes the program to not work. I want the program to work and have a different extension. Is this is possible could anyone show me how its done.
: : : :
: : : : --Digga
: : : :
: : : :
: : :
: : : Your OS uses the file extension to determine how and where to read the PSP header in your executable. If you rename the file then the OS will assume that it is not an executable and not run it.
: : :

: : :
: :
: : maybe. please read my previous posts.
: : :
: :
: :
:
: I know you can rename a file but to execute it with the new file extension should fail since the PSP isn't being translated by the OS. If the OS doesn't know what kind of executable it is from some of the basic types like PE, MZ, COM, ect. then how would it know how to read the PSP? Is there a function in the Winapi that could execute the code by calling the renamed program? I would be curious to know of such.
:

:
:
:


I just renamed an *.exe file to a *.asd file and it ran fine when calling it via the command prompt, so I tried it progmatically with CreateProcess() and it runs the changed file .ext as normal.


To understand recursive, first you need to understand recursive

Report
Re: How to change a file extension. Posted by stober on 2 Jul 2005 at 9:56 PM
:
: I just renamed an *.exe file to a *.asd file and it ran fine when calling it via the command prompt, so I tried it progmatically with CreateProcess() and it runs the changed file .ext as normal.


AhHa! Finally someone who knows what the hell he is talking about!
Report
Re: How to change a file extension. Posted by DB1 on 2 Jul 2005 at 9:59 PM
: :
: : I just renamed an *.exe file to a *.asd file and it ran fine when calling it via the command prompt, so I tried it progmatically with CreateProcess() and it runs the changed file .ext as normal.
:
:
: AhHa! Finally someone who knows what the hell he is talking about!
:

LOL Stober I can see you banging your head on the keyboard trying to explain it three times!
To understand recursive, first you need to understand recursive

Report
Re: How to change a file extension. Posted by will112 on 2 Jul 2005 at 9:43 PM
: I want to know if I can change a file extension of a program. Instead of the program saying .exe I want it to say something else. Now I know that I can change the file etension through DOS, but it causes the program to not work. I want the program to work and have a different extension. Is this is possible could anyone show me how its done.
:
: --Digga
:
:


The rename through widows works, it just depends on what you are doing. You can change a .txt to a .doc. or a .exe to a .com. But you can't change a txt file to a exe file and stuff like that. What exactly is it you are doing?
Report
Re: How to change a file extension. Posted by stober on 2 Jul 2005 at 9:52 PM
:
: The rename through widows works, it just depends on what you are doing. You can change a .txt to a .doc. or a .exe to a .com. But you can't change a txt file to a exe file and stuff like that. What exactly is it you are doing?
:


I'll say this one more time -- for the third time -- You can name a file anything you want. Change a text file to have .exe, .com, .bat or any other extension. Windows doesn't give a crap what you call it. However, that does not mean that a text file can be executed just by renaming it to have .exe extension.
Report
Re: How to change a file extension. Posted by IDK on 3 Jul 2005 at 2:32 AM
: :
: : The rename through widows works, it just depends on what you are doing. You can change a .txt to a .doc. or a .exe to a .com. But you can't change a txt file to a exe file and stuff like that. What exactly is it you are doing?
: :
:
:
: I'll say this one more time -- for the third time -- You can name a file anything you want. Change a text file to have .exe, .com, .bat or any other extension. Windows doesn't give a crap what you call it. However, that does not mean that a text file can be executed just by renaming it to have .exe extension.
:
Cool, I didn't think of the header in the exe...

Does it send all executables to the same place?
But what If I had a textfile that began like
the header? Would it run it?

Niklas Ulvinge aka IDK

Report
Re: How to change a file extension. Posted by stober on 3 Jul 2005 at 9:33 AM
:
: Does it send all executables to the same place?
I don't know what you mean by that. Search your hard drive for *.exe files and you will easily see that they are not all in one folder (unless you are using MS-DOS Version 1.0 where everything was in the root directory)
: But what If I had a textfile that began like
: the header? Would it run it?
Text files can't have a header like an executable because the headers contain binary information, not text format. A text file that contains binary information is NOT a text file.
:

Report
Still confused Posted by Digga on 3 Jul 2005 at 11:02 AM
This message was edited by Digga at 2005-7-3 11:2:49

I either don't understand or I'm doing it wrong. Maybe I need to tell you All what I'm doing. I am making a program that farts when the user double clicks on it. I gave the program a microsoft word icon. Now if I was to email this to a friend of mine, they would see that its an executable. I want it that the program say .doc at the end of it. Now also I think it would be neat to change the extensions. now I did the dos prompt thing and programed it. I just don't get it. Here's what I did.


Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\WINDOWS>cd C:\Documents and Settings\Owner\Desktop

C:\Documents and Settings\Owner\Desktop>ren MyProgram.exe MyProgram.doc

C:\Documents and Settings\Owner\Desktop>



When I do this it changes the extension. But when I click on the program it does not do what's its supposed to and it opens as a word document. Now if I make up a file extension such as .aaa it creates some file that when clicked on asks me that it cannot open it but would I like to open it with something else. Same thing happpens if you use the rename function or system function. Maybe I need to use that create process function. I just do not understand.

Digga


Report
Re: Still confused Posted by DB1 on 3 Jul 2005 at 2:49 PM
: This message was edited by Digga at 2005-7-3 11:2:49

: I either don't understand or I'm doing it wrong. Maybe I need to tell you All what I'm doing. I am making a program that farts when the user double clicks on it. I gave the program a microsoft word icon. Now if I was to email this to a friend of mine, they would see that its an executable. I want it that the program say .doc at the end of it. Now also I think it would be neat to change the extensions. now I did the dos prompt thing and programed it. I just don't get it. Here's what I did.
:
:
: 
: Microsoft Windows XP [Version 5.1.2600]
: (C) Copyright 1985-2001 Microsoft Corp.
: 
: C:\WINDOWS>cd C:\Documents and Settings\Owner\Desktop
: 
: C:\Documents and Settings\Owner\Desktop>ren MyProgram.exe MyProgram.doc
: 
: C:\Documents and Settings\Owner\Desktop>
: 
: 

:
: When I do this it changes the extension. But when I click on the program it does not do what's its supposed to and it opens as a word document. Now if I make up a file extension such as .aaa it creates some file that when clicked on asks me that it cannot open it but would I like to open it with something else. Same thing happpens if you use the rename function or system function. Maybe I need to use that create process function. I just do not understand.
:
: Digga
:
:
:


Stober already explained that when you change the file extension, it will not work properly when clicked on in explorer. Explorer obviously uses the file extension to figure out how to open a file, and if you rename it to a .doc file, then explorer will always open it up in wordpad.

You can run the renamed program as usual only if you start it programatically or if you run it from the command prompt (type MyProgram.doc at the command line and it will run properly) but it just wont work like that in explorer.

You cannot just change the file extension and send it to a friend hoping that he sees MyProgram.doc and thinks it's a document, but when he clicks on it, it will run as an executable. That would be a bad thing and if it were that easy then hackers would have an easy time infecting everyone's computer.

Now there are a few other file extensions that you could use which will run as executables when clicked on (try renaming it to a .pif) but there is no way to hide it as a .doc or a .bmp



To understand recursive, first you need to understand recursive

Report
Re: How to change a file extension. Posted by IDK on 4 Jul 2005 at 3:08 AM
: :
: : Does it send all executables to the same place?
: I don't know what you mean by that. Search your hard drive for *.exe files and you will easily see that they are not all in one folder (unless you are using MS-DOS Version 1.0 where everything was in the root directory)
: : But what If I had a textfile that began like
: : the header? Would it run it?
: Text files can't have a header like an executable because the headers contain binary information, not text format. A text file that contains binary information is NOT a text file.
: :
:
:
What I wanted to ask was:
Is the loader the same for any of these executable formats
The loader that loads the .exe and .com files.

What If I did a binary file that just happend to begin like the
.exe header? Would it execute?

Niklas Ulvinge aka IDK

Report
Re: How to change a file extension. Posted by stober on 4 Jul 2005 at 7:58 AM
:
: What If I did a binary file that just happend to begin like the
: .exe header? Would it execute?
:

copy some *.exe to a temp directory, then strip all but the header from the file. try to run it and see what happens.
1 2  Next



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.