tags:

views:

81

answers:

3

Greetings,

I want to know simply how to create a batch file from .exe file?

Thank you.....

+2  A: 

If you mean you want to create a new batch file from an unrelated existing executable file (in other words, the batch file does something different), you do it the way you create any file. In C, you'd use fopen, fwrite and fclose to create your new file and write whatever batch file commands you want to it.

If you mean you want to create a batch file that "intercepts" your exe file, you can do that too. If your executable file is pax.exe, you can simply rename it to pax2.exe and create a batch file called pax.cmd thus:

@echo off
pax2.exe

This will allow you to do arbitrary actions before and after your executable runs but there are things to watch out for such as executables that return control before they're actually finsihed.

If, however, you're talking about converting an arbitrary executable into a batch file that performs the same task, that's much more difficult. Unless you have the source code or a very good specification on how the executable works, you're going to have a lot of trouble.

Automating the conversion for anything but the simplest executable will be insanely difficult.


And, if you want a link to a batch file that runs your executable, just create the batch file (say in c:\bin\pax.cmd) containing:

@echo off
c:\bin\pax.exe

and then create a shortcut to it from wherever you want (such as the desktop). You could even put the batch file itself in your desktop directory but I'm not a big fan of that. However, to each their own.

paxdiablo
I want to make a .bat file to run .exe file...I have test.exe file in my Desktop. I want to create test.bat on my desktop, so when i click on it, it will run the .exe file.Is this possible?
Davideg
@Davideg: yes, that's similar to my second option above and almost exactly identical to my fourth option, which appears to have miraculously and spontaneously formed for no reason whatsoever :-)
paxdiablo
so, you mean that I create test.txt file and write on it the 2 lines:@echo offc:\bin\test.exethen I rename this file to test.bat. and that`s it.I did this scenario but it didn`t work out.Did I forget any detail?
Davideg
@Davideg, that was sample code I gave, it's unlikely that your `test.exe` file will be in `c:\bin`. You need to put its _actual_ path into the batch file.
paxdiablo
@paxdiablo, What you mean by "unlikely that your test.exe file will be in c:\bin". you always mention c:\bin => is it essential to use this directory or not.
Davideg
No, it's not. You should use directories suited to your environment. I have a `c:\bin` because I always create one to dump all those little goodies that I need without having to add hundreds of different directories to my PATH. You should put your batch file where you want (e.g., create a `My Documents\batchfiles` for it). The batch file itself should contain the _full path of the executable._ Example, if the executable was `c:\europa\eclipse.exe`, _that's_ what you would use. You need to use the path where your `test.exe` actually is.
paxdiablo
+1  A: 

simply use notepad.exe

load a note pad. write anything let say '@echo off'

Save it! with filename sample.bat :)

XBasic3000
hahaha you make me lough...... but your right...
simply_anny
Well, I suppose notepad.exe is technically an "exe file" but I'm not sure that's what the OP was getting at :-)
paxdiablo
well he didnt mention to create an .exe file that create a batchfile. notepad is an exefile. heheh
XBasic3000
but what he really mean is how to execute and exefile using the batchfile..
XBasic3000
@XBasic3000 yes, you r right. I have .exe file for a c# cosole application.
Davideg
+2  A: 

whatever you do in the CMD.Exe or commandline you can write it also as a batch file

example

goto menu->run type cmd.exe

type dir/w

as you can see it display the content of the current drive\folder.

See dos commands there are sample of basic usage of it. @echo off means hiding the output message on the screen. so its better not to use it when procticing so that you could see whats happing

examples sample.bat

cd\
md hello
cd hello
notepad.exe

as you can see you created a 'hello' folder on your drive C: and notice notepad.exe executed. take note that notepad.exe is in the windows directory wich inclue on the windows path. so if you want to execute file wich is not in the windows path, then you must include the filename path ex: c:\bin\your.exe

XBasic3000