我已经创建了一个批处理文件,它在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组成的压缩文件,我如何在复制后使其能够在另一台PC上运行?
任何帮助都将不胜感激。
发布于 2016-04-24 06:47:52
如果“可移植”目录将包含所有可执行文件,另一种方法是将.bat脚本的位置设置为当前工作目录。
@ECHO OFF
PUSHD "%~dp0"
: do things, the directory of the .bat script is the current directory
POPD
EXIT /B 0发布于 2016-04-23 01:13:32
将工具放入与批处理文件相同的文件夹中,而不是
C:\Users\kumar\Desktop\CCleaner.exe做
%~dp0\CCleaner.exe%~dp0是批处理文件的Drive和Path。
您还可以将您的工具放入子目录(tools),然后:
%~dp0\tools\CCleaner.exe发布于 2021-07-28 06:00:36
如果你的应用程序使用了一些系统变量(例如PATH),并且你可能想要在启动应用程序之前在本地重新分配它们,那么This可能会很有用。所提供的.exe将把控制传递给一个.bat,您可以在其中执行此操作以及执行更多操作。在此.bat的末尾运行App.exe
https://stackoverflow.com/questions/36799670
复制相似问题