2016-04-22 84 views
0

我创建了一个批处理文件,它在Windows命令提示符下运行多个命令,这很好,但是,我想通过相同的批处理文件运行可移植的exe文件。例如。如果我的zip文件传输到另一台计算机,所有我想要做的是运行批处理文件和便携式exe文件将与其他命令的最后一个条件我一起运行,以及通过批处理文件运行Portable 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文件,我将如何使它在复制后在另一台PC上运行?

任何帮助,将不胜感激。

回答

0

地方你的工具到相同的文件夹和批处理文件,而不是

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

%~dp0\CCleaner.exe 

%~dp0d里沃和您的批处理文件的P ATH。

你也可以把你的工具集成到一个子目录(tools)和:

%~dp0\tools\CCleaner.exe 
1

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

@ECHO OFF 
PUSHD "%~dp0" 

: do things, the directory of the .bat script is the current directory 

POPD 
EXIT /B 0 
相关问题