I need to create a .exe file that opens an .html document with the default browser.
In command prompt, start myfile.html works, but I don't know how to turn that into an .exe file.
How can I do that please?
Thank you.
Quite useless IMHO... Anyway use a .BAT file instead and use some app around there that converts .BAT to .EXE.
Why not just use a .bat file? Much less hassle than compiling an .exe. As well, in Windows, double-clicking the .html file would open it in the default browser anyways, so you're not gaining much.
I'd echo the questions about why you'd want to do this, but if you really insist on doing it, it shouldn't be terribly difficult.
#include <windows.h>
int main(int argc, char **argv) {
if (argc !=2) {
MessageBox(NULL, "Usage: exec_html <html_file>", "Usage Error", MB_OK);
return 1;
}
if ((int)ShellExecute(NULL, "open", argv[1], NULL, NULL, SW_SHOWNORMAL) < 32) {
MessageBox(NULL, argv[1], "Could not open file", MB_OK);
return 1;
}
return 0;
}
Compile with a C or C++ compiler of your choice. If (as sounds like the case) you don't normally use either, the easiest way to go is probably get Microsoft Visual C++ Express, a free (as in beer) download.
First download a bat to exe converter here, then open notepad and type the following:
#echo off
start myfile.html
exit
Save it as whatever you want (.bat) and then start bat to exe converter and select the batch file and click the compile button.
This way works and too everyone wondering why you might want to do this, I infact have been looking everywhere for this and am glad I found it. I needed to make a ZIP file and inside I needed my game to be runable through an exe file and my game could only be run through HTML so I found this and have been able to do so. :)
You can use ShellExecute with "open" as verb from C or C++.
First download bat to exe converter from the following link:
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
Then open notepad and type the following:
#echo off
start myfile.html
exit
Save it as whatever you want.bat and then start bat to exe converter and select the batch file and click the compile button.
Now you get the exe file you wanted.
Related
I am trying to compile on mingw a program that prints to console using Windows.h functions. Why do I get no output?
C file:
#include <Windows.h>
int main() {
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsoleA(out, "hello", 5, NULL, NULL);
return 0;
}
To print to a console your application must be a console application in the first place. A Windows GUI application can
Make sure you linked the application using the -mconsole flag.
Also make sure that you are not running the application from somewhere where the output may disappear right away (like an IDE). Instead open a command prompt and run your .exe file from there to see the output. Or you could add some code to wait for a key in your code so you can see the output before the window closes automatically.
I was wondering if it was possible to run a selfwritten ruby program just like any other program by double-clicking an icon of some sort.
And if it's possible, how do I do it?
I wrote a little program for a friend but I don't want him to have to use the command line to run it, because that's rather inconvenient (unless there is a way to just double-click and the command line opens the program itself..).
Thanks for your help!
The simple answer that should work for all versions of Windows is to just create a simple batch launcher.
Create a .bat file. I usually just create a new .txt file via "right click > new > text document". Then rename it, highlight everything, including the extension, and rename it to something like run.bat. The .bat part is important. Once you rename it, the icon should change to gears. If you can't overwrite the extension, or Windows is still treating it as a text document, you'll need to either manually save it as a bat, or disable "hide file extensions" in the explorer settings so the extension can be changed.
Edit the bat file, and put into it something like:
#echo off
YOUR RUN COMMAND HERE THAT YOU WOULD NORMALLY TYPE MANUALLY
pause
Paste the command that you would normally run manually where the capital text is. The first line is so it doesn't repeat the commands back, and the pause is so if an error happens, the command prompt doesn't immediately close. This gives you a chance to read the error.
Save it and close it. Now, if you double click on the bat file, your program should run.
Multiple ways
if it's for occasional use and for one script only I would pack it
to a Windows executable with Ocra, then you can double click
the .exe itself or a link to it
same as above but use jRuby and create a .jar file, not for beginners though
the easiest: if you configure Windows to start/run .rb files with your ruby.exe you can double click the .rb files itself and they
will execute, they will have the red Ruby stone icon
if you run a .reg file to enable drap and drop on .rb files you can combine the previous technique to drop files on the script and
they will be the parameters to the script, see my answer here for the reg file
my favorite: copy the .rb to your windows "C:\Users\your_user\AppData\Roaming\Microsoft\Windows\SendTo\"
folder, then you can right click file(s) or folder(s) and select
sendto and select your script, the files or folder will again be the
parameters for your script
you can create a .bat or .cmd file that starts with the path to your ruby.exe and the script as parameter, use rubyw.exe if you
don't want output
Here is my bat script (TestBatScript.bat):
set /p args=Enter some args:
TestApp.exe %args%
pause
For this script to work I have to have TestApp.exe and TestBatScript.bat in the same folder. Is it possible to include these two files in one file .bat or .exe or whatever?
If this is what you are asking for, you can't aggregate batch file with exe file. Indeed exe file are compiled file (open it on a text editor, you won't be able to read it). Batch files are scripts that are interprated by terminals.
If you can recompile your exe file, you can add to source code to pass argument with hands (for instance use scanf in C, ...) if there is no argument passed by the system
int main(int argc, char** argv) {
if(argc==0) {
/* get here the argument (no argument passed)*/
}else {
/* use here argument passe to your function */
}
/* Do stuff */
}
You can use Iexpress that is a built in program in your windows OS. To access it hir win+R and then type iexpress or iexpress.exe. Do some experiments and you will eventually understand. Here is the Wikipedia in case want it. And Here is a tutorial on How to use it.
This following code in my bat file copy's the bat file while it's running into a correct directory in windows 7 but when I convert it to a exe script it no longer works.
Can any one suggest a alternative ? Or any suggestions to why?
if not exist "%programfiles%\toolset\" (
md "%programfiles%\toolset\"
copy "%~f0" "%programfiles%\toolset\"
)
can any one else help I'm pretty sure it's not my converter tool I use as I have tried all the ones listed below but I think the script needs editing for it to function as exe application?
You can try the following nice tool
http://www.battoexeconverter.com/
since you are accessing programfiles you need to be admin
To do this run the cmd in admin mode and try to execute in command line
Download this tool. It works well.
Bat2Exe
You can add administrator manifest to run as administrator when opening the exe file.
I am a batch programmer just like you.
Personally I use this tool;
http://www.f2ko.de/programs.php?lang=en&pid=ob2e
Nice tool, only requires a download, used it multiple times, never dissappointed me, and it is very legit, have no doubts about it!
Pringles
It is very stupid that windows will not let you add batch files to your quick launch or whatever they call in in windows 7. That bar across the bar, i can attach firefox there, command prompt, even paint (my favorite), but not a batch file. I can "pin" it to another program, which is just weird. I want it to standalone, the batch file does enough work by itself.
So lets say i have batch file. What is the simplest executable program I can write to invoke said script. Then I can finally pin all my useful batch files on that quick-jump-pin-bar.
If I remember right, you can do this by first pinning a shortcut to CMD.exe to the taskbar. Then edit the command, and change CMD.exe to CMD.exe /c MyBatchFile.bat. I believe this will execute the batch file.
Since you can only pin one cmd, here's an alternative, assuming you have the .NET framework installed - a very simple C# application:
Populate a textfile with the following contents:
class Program {
static void Main() {
System.Diagnostics.Process.Start(#"c:\test.bat");
}
}
where Program is the name of the executable you want to create, and c:\test.bat is the full path to the batch file. Save the file as Program.cs. Execute the following from the command line:
c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe Program.cs
You can replace 2.0.50727 with whatever directory exists on your machine - might be 1.1.something or 3.5 or 4.0.something - it's all the same for this scenario.
This will generate Program.exe. You can put that exe file wherever you want, and pin that executable to the taskbar. You can discard the .cs file once you're done making your executables.
Kind of a crappy solution, but it should work, assuming you don't find anything better. And if you don't have the .NET framework (which I'm not sure is even possible in Windows 7), you can install it pretty easily.
The easiest way is to create a folder, put your batch files in it, and pin the folder to the menu bar :D
You can also write a startup script, so the batch file will be executed on startup, but I don't know if you want to run those scripts on every bootup... You can also add the command prompt to the bar, and edit the startup path..
Use command switches on CMD.exe.
cmd.exe /c "myscript.bat"
As a sort of workaround you could use the following trick. Pin an arbitrary application to the task bar, Shift+right click on the pinned icon, select Properties, change 'Target' and 'Start in' accordingly. Rename it too if you like.
You can pin more than one .bat file using this technique.