windows 创建 .exe 文件以打开 .html 文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7982836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create .exe file to open .html document
提问by Francisc
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?
我需要创建一个 .exe 文件,用默认浏览器打开一个 .html 文档。在命令提示符下,start myfile.html
有效,但我不知道如何将其转换为 .exe 文件。请问我该怎么做?
Thank you.
谢谢你。
采纳答案by m0skit0
Quite useless IMHO... Anyway use a .BAT file instead and use some app around there that converts .BAT to .EXE.
恕我直言,相当无用...无论如何使用 .BAT 文件,并在那里使用一些将 .BAT 转换为 .EXE 的应用程序。
回答by Marc B
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.
为什么不直接使用 .bat 文件?比编译 .exe 少很多麻烦。同样,在 Windows 中,双击 .html 文件无论如何都会在默认浏览器中打开它,因此您不会获得太多收益。
回答by Jerry Coffin
I'd echo the questions about whyyou'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.
使用您选择的 C 或 C++ 编译器进行编译。如果(听起来是这样)您通常不使用它们,最简单的方法可能是获取Microsoft Visual C++ Express,免费(如啤酒)下载。
回答by 0Bennyman
First download a bat
to exe
converter here, then open notepad and type the following:
首先下载一个bat
来exe
转换这里,然后打开记事本,输入以下命令:
@echo off
start myfile.html
exit
Save it as whatever you want (.bat
) and then start bat to exe converterand select the batch file and click the compile button.
将其另存为您想要的任何内容 ( .bat
),然后启动bat 到 exe 转换器并选择批处理文件并单击编译按钮。
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. :)
这种方式有效,每个人都想知道你为什么要这样做,事实上我一直在到处寻找这个,很高兴我找到了它。我需要制作一个 ZIP 文件,在里面我需要我的游戏可以通过 exe 文件运行,而我的游戏只能通过 HTML 运行,所以我发现了这个并且已经能够这样做。:)
回答by Norbert Willhelm
You can use ShellExecutewith "open" as verb from C or C++.
您可以将ShellExecute与“open”一起用作 C 或 C++ 中的动词。
回答by Pranav
First download bat to exe converter from the following link:
首先从以下链接下载 bat 到 exe 转换器:
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
Then open notepad and type the following:
然后打开记事本并输入以下内容:
@echo off
@echo off
start myfile.html
start myfile.html
exit
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.
将其另存为您所需要的任何内容want.bat
,然后启动 bat 到 exe 转换器并选择批处理文件,然后单击编译按钮。
Now you get the exe file you wanted.
现在你得到了你想要的 exe 文件。