Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello, i was just thinking, how can i compile an exe that runs in both windows and dos? An nice example is windows98's regedit.exe. I dont really need it but i'm just curious how can it be done.
Cheers

Not sure what you mean. Regedit is a windows GUI program. Sure, you can start it from the command prompt, but that's not DOS. DOS is an older operating system (that the command prompt is based off of) that used to ship with Windows. Now all that's left is the weak command prompt.
Now if you want to write a program that either runs in GUI style or in text based old school DOS, I seem to remember ways to do that. I think you would just bundle two versions of the program together, one linked with the Windows SDK, and one built for dos, and have the main executable start one or the other depending on the environment. As to determining the environment, I can't remember how its done, but a google search should reveal some info.

Not possible. Two different environments. It's like putting diesel in a petrol engine.
Regedit.exe may be able to be called from DOS, but it is running from Windows. Try running it from a pure DOS environment. It will probably try to load Windows. DOS has no knowledge of a registry or anything to do with it.
Even Regsver32 which is nearly always called from a DOS command line but it is in fact a Windows programme.
If fact if you call most Windows programme from a DOS prompt within windows, it will run, but its running under Windows, not DOS.
Stuart

Thanks, shipping 2 versions of my exe vould be nice. However there definitly is a way how to make it all-in-one.
Of course, creating console mode applications is easy. But regedit really runs in PURE DOS. In fact, all programs run in pure dos. But they all have code at the very beginning of file that checks if the program is running under pure dos. If yes, the code prints message "This program cannot be run in dos mode" and ends. Sure, when regedit is started form windows, its gui-based(because the windows part of the exe loads). But when started from dos(not command line) it is also usable. It will become command-line program. So an usage from PURE dos vould be like this
regedit -d HKEY_LOCAL_MACHINE etc.
I dont remember the commands, because i dont have win 98 installed right now.
If you open a classic win exe in hexeditor, you will see something like
bla bla bla This program cannot be run in dos mode. bla bla
thats the dos-code. However windows 98's regedit.exe doesnt look like this in hexeditor. It looks totally different. It doesnt even have the cant run message.
So my question is: how can i modify the code that runs in pure dos mode? How big can my code for dos be? Thanks

>> But regedit really runs in PURE DOS. In fact, all programs run in pure dos.<<
I don't know who told you that, but they told you wrong.
"This program cannot be run in dos mode" was only put there in the early days of Windows when there were still a lot of people around familiar with DOS. The fact that you can enter command line parameters is irrelevant.
Modifying any programme to run in an environment different than it was designed for simply by modifying is impossible. There are just to many things that need changing. Even if it were possible, you would need the source code.
Remember, DOS is a 16 bit single user, single taking environment. Windows is a 32 bit multi user, multitasking environment. Windows programmes have to be written to take that into account.
Stuart

I have found a copy of windows95's regedit.exe. It appears that it is also usable from dos. Ill show why.
Please go to theese addresses. I have placed very descriptionable pictures there. Its because of my english. If youll see the pictures, youll surely know what i mean.
www.goosemaster.szm.sk/normal.jpg
And second:
www.goosemaster.szm.sk/regedit.jpg
Thanks!

If you are curious on the exe file itself, download from here:
www.goosemasrer.szm.sk/regedit.exe
Give it a try, and run form pure dos using some diskette or something!

A program created for windows cannot be run in dos but a program created for dos can be run in windows
I have created commandline programs in basic that run in windows and Dos
and programed visual basic6 gui programs for windows only
there is an old outdated version of visual basic for dos I havent used it yet
but I am assuming it would do what you ask
http://imaginatica.us.es/~wopr2k/qbdl/index.html#visualbasic
ive been meaning to try it myself let me know how it worksMy Page has many quick explainations of basic commands
Feel free to contribute Or enlighten me with code examples that are not on my page
I am particularly interested in learning hardware periph

Thank you for all your answers. VBDOS create dos-only programs that, yes, work in windows. But thats not what i want to do.
Have some of you looked at the pictures, or have you downloaded the exe? Please, if no, then i understand what you are talking to me. I have also never seen an exe that executes normally in windows and dos too. I came accross that by this way:
I was reading "tips and tricks for windows 98". In one trick there was said: "Do you know that regedit runs also in DOS?"
At the first look, i thinked the SAME as all of you. "What?!? That cant be true!"
But, i could not not-try it. So i have choosed "Restart computer in MS-DOS mode" and launched regedit.exe. Whoala! Runs like a simple command-line parameters based program. Under windows runs like a gui program. (because different parts of exe loads) All i want to do is to tell the compiler(preferably c++) to write the dos portion of exe with MY CODE.
Maybe runs is not a correct word. I want to make a program that *behaves* differently under dos than printing "this program cannot be run in dos mode." I know that now you must think "why are you still asking, even if i said thats not possible!". Sorry, but it is. Download the exe. Run from PURE DOS using some startup diskette. The exe speaks for itself. So the pictures do.

Yes now i got it. The dos-part of exe is called dos stub. Info on website
http://win32assembly.online.fr/pe-tut1.html
So, dont you please know how can i change the dos stub? You see, "can simply display a string like "This program requires Windows" or it can be a full-blown DOS program depending on the intent of the programmer."
I volud like my program to be compatible with dos! Please somebody dont know the solution?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |