无需额外的外部软件即可将 .bat 转换为 .exe(创建 SFX) [英] Converting .bat to .exe with no additional external software (Create SFX)

查看:33
本文介绍了无需额外的外部软件即可将 .bat 转换为 .exe(创建 SFX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照与此相同的步骤

;@echo off;Title 使用 iexpress 将批处理脚本转换为 file.exe;模式 75,3 &颜色 0A;Rem 原创脚本 https://github.com/npocmaka/batch.scripts/edit/master/hybrids/iexpress/bat2exeIEXP.bat;回声(;如果 "%~1" 等于 "" (;echo 用法:将批处理文件拖放到此脚本上:"%~nx0";超时/T 5/nobreak>nul &出口;);设置target.exe=%__cd__%%~n1.exe";设置batch_file=%~f1";设置 "bat_name=%~nx1";设置 "bat_dir=%~dp1";设置 "sed=%temp%2exe.sed";echo 请稍等...正在创建%~n1.exe"...;copy/y "%~f0" "%sed%" >nul;(;(回声();(echo(AppLaunched=cmd/c "%bat_name%");(echo(目标名称=%target.exe%);(echo(FILE0="%bat_name%");(回声([源文件]);(echo(SourceFiles0=%bat_dir%);(回声([SourceFiles0]);(回声(%%FILE0%%=);)>>"%sed%";iexpress/n/q/m %sed%;del/q/f "%sed%";退出/b 0[版本]类=IEXPRESSSED版本=3[选项]PackagePurpose=安装应用程序显示安装程序窗口=0隐藏提取动画=1使用长文件名=1内部压缩=0CAB_FixedSize=0CAB_ResvCodeSigning=0重启模式=N安装提示=%安装提示%显示许可证=%显示许可证%FinishMessage=%FinishMessage%目标名称=%目标名称%友好名称=%友好名称%应用启动=%应用启动%PostInstallCmd=%PostInstallCmd%AdminQuietInstCmd=%AdminQuietInstCmd%UserQuietInstCmd=%UserQuietInstCmd%源文件=源文件[字符串]安装提示=显示许可证=完成消息=友好名称=-PostInstallCmd=<无>AdminQuietInstCmd=

Following the same steps as this guide. I am trying to convert from bat to exe without installing any new software such as Bat to Exe Converter. The reason I am using this method is because all machines in my workplace already have 7zip installed and can use it, however I am not allowed to make the script work using external software not present on the main server to be compatible on any machine in the company.

I have the following TEST.bat:

ECHO This is a Test bat to exe
pause

and the config.txt:

;!@Install@!UTF-8! 
RunProgram="TEST.bat" 
;!@InstallEnd@! 

then I call the following command line (in another .bat):

COPY /B "%PathTo7Zip%7zCon.sfx" + %Config% + %Source7ZFile% %OutputFile%

%PathTo7Zip% is the directory to 7zCon.sfx %Config% is the config.txt file above %Source7ZFile% is my .7z archive and %OutputFile% is my output TEST.exe file which should supposedly run the bat file when I call it according to the author of the guide. However calling TEST.exe triggers unzipping the .7z archive (which is expected) and then exits without running TEST.bat.

However the author explains:

Conclusion:

It is important to note that while the resulting file runs exactly the same as the source BAT file, this is not a true batch to executable conversion. The resulting file is an EXE, however it is intended to be used for self-extracting installers. When you execute the resulting EXE file, the process goes something like this:

  1. The contents of the EXE file are extracted to the temp directory.
  2. The config file generated by the script is read.
  3. The batch file contained in the EXE file is executed in a new command window.
  4. Once finished, the temp files are removed.

解决方案

Refer to this How can a .bat file be 'converted' to .exe without third party tools?

The original script accepts two arguments - the .bat file you want to convert and the target executable.

I made a little modification to accept one argument : Just the .bat file you want to convert.

So in this case, you can drag and drop your batch file over this script bat2exeIEXP.bat and it will be converted to exe file with the same name as the batch file.

;@echo off
;Title Converting batch scripts to file.exe with iexpress
;Mode 75,3 & color 0A
;Rem Original Script https://github.com/npocmaka/batch.scripts/edit/master/hybrids/iexpress/bat2exeIEXP.bat
;echo(
;if "%~1" equ "" (
    ;echo  Usage : Drag and Drop your batch file over this script:"%~nx0"  
    ;Timeout /T 5 /nobreak>nul & Exit
;)
;set "target.exe=%__cd__%%~n1.exe"
;set "batch_file=%~f1"
;set "bat_name=%~nx1"
;set "bat_dir=%~dp1"
;Set "sed=%temp%2exe.sed"
;echo              Please  wait a while ...  Creating "%~n1.exe" ...
;copy /y "%~f0" "%sed%" >nul
;(
    ;(echo()
    ;(echo(AppLaunched=cmd /c "%bat_name%")
    ;(echo(TargetName=%target.exe%)
    ;(echo(FILE0="%bat_name%")
    ;(echo([SourceFiles])
    ;(echo(SourceFiles0=%bat_dir%)
    ;(echo([SourceFiles0])
    ;(echo(%%FILE0%%=)
;)>>"%sed%"

;iexpress /n /q /m %sed%
;del /q /f "%sed%"
;exit /b 0

[Version]
Class=IEXPRESS
SEDVersion=3
[Options]
PackagePurpose=InstallApp
ShowInstallProgramWindow=0
HideExtractAnimation=1
UseLongFileName=1
InsideCompressed=0
CAB_FixedSize=0
CAB_ResvCodeSigning=0
RebootMode=N
InstallPrompt=%InstallPrompt%
DisplayLicense=%DisplayLicense%
FinishMessage=%FinishMessage%
TargetName=%TargetName%
FriendlyName=%FriendlyName%
AppLaunched=%AppLaunched%
PostInstallCmd=%PostInstallCmd%
AdminQuietInstCmd=%AdminQuietInstCmd%
UserQuietInstCmd=%UserQuietInstCmd%
SourceFiles=SourceFiles

[Strings]
InstallPrompt=
DisplayLicense=
FinishMessage=
FriendlyName=-
PostInstallCmd=<None>
AdminQuietInstCmd=

这篇关于无需额外的外部软件即可将 .bat 转换为 .exe(创建 SFX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆