【问题标题】:Running Portable Exe file through batch file通过批处理文件运行便携式 Exe 文件
【发布时间】:2016-04-22 17:09:14
【问题描述】:

我创建了一个批处理文件,它在 Windows 命令提示符下运行多个命令,它工作得很好,但是,我也想通过同一个批处理文件运行一个可移植的 exe 文件。例如。如果我将 zip 文件传输到另一台计算机,我想做的就是运行批处理文件,并且便携式 exe 也将与其他命令一起运行

:start
cls
color 1A
cls
@echo off
echo. 
echo. 
echo.
echo ********************************************
echo ************* Test Program **************
echo ********************************************
echo. 
echo. 
echo.
echo 01) System information
echo 02) Ping
echo 03) IP configuration
echo 04) Verify Drivers
echo 05) Driver List 
echo 06) Get Serial Number 
echo 07) Disk Defragmentation 
echo 08) DiskPart 
echo 09) Repair Load Preferences 
echo 10) Run CCleaner 
echo.
REM This is a test program 
REM echo This is a Test Program 
set /pnum= Type the corresponding number to perform an operation: 
if %num%==01 (
cls
systeminfo 
)
if %num%==02 (
cls
ping www.google.com
)
if %num%==03 (
cls
ipconfig /all
)
if %num%==04 (
cls
verifier
)
if %num%==05 (
cls
driverquery
)
if %num%==06 (
cls
wmic bios get serialnumber
)
if %num%==07 (
defrag c: /a 
pause
cls
)
if %num%==08 (
diskpart 
pause
cls
)
if %num%==09 (
cls
lodctr /r /f
echo.
pause
)   
if %num%==10 (
cls 
C:\Users\kumar\Desktop\CCleaner.exe
echo.
pause)

    set /p choice="Do you want to restart? Press 'Y' to continue, or any other key to exit: "
if '%choice%'=='y' goto start

例如,在最后一种情况下,我正在运行目前在桌面上的 CCleaner,但是如果我复制一个包含 BAT 文件和 CCleaner.exe 的 zip 文件,我将如何让它在另一个上运行复制后的电脑?

任何帮助将不胜感激。

【问题讨论】:

    标签: windows batch-file cmd zip portable-executable


    【解决方案1】:

    如果“可移植”目录将包含所有可执行文件,另一种方法是将.bat 脚本的位置设为当前工作目录。

    @ECHO OFF
    PUSHD "%~dp0"
    
    : do things, the directory of the .bat script is the current directory
    
    POPD
    EXIT /B 0
    

    【讨论】:

      【解决方案2】:

      将您的工具放在与批处理文件相同的文件夹中,而不是

      C:\Users\kumar\Desktop\CCleaner.exe
      

      %~dp0\CCleaner.exe
      

      %~dp0 是您的批处理文件的 Drive 和 Path。

      您也可以将工具放入子目录 (tools) 并且:

      %~dp0\tools\CCleaner.exe
      

      【讨论】:

        【解决方案3】:

        This 在您的应用使用某些系统变量(例如 PATH)的情况下可能很有用 并且您可能希望在启动应用程序之前在本地重新分配它们。提供的 .exe 会将控制权传递给 .bat,您可以在其中执行此操作等等。 在这个 .bat 结束时运行 App.exe

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-01-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多