楼 主
[求助]文件拖动到批处理后的参数问题
发表于 2008-03-03 13:44 · 中国 重庆 电信
初级用户
★
积分 34
发帖 14
注册 2007-12-13 18:21
18年会员
UID 105563
性别 男
状态 离线
if exist autorun.inf goto exist
echo.>autorun.inf
:exist
echo [autorun]>> autorun.inf
echo icon=%1>> autorun.inf
pause
以上是一个制作U盘图标的代码,如果直接运行可以生成autorun.inf的文件,但是如果拖动一个图标文件到该批处理时就不能生成autorun.inf文件,而且发现运行的代码也比较奇怪。高手请教一下。
第 2 楼
发表于 2008-03-03 15:10 · 中国 上海 联通
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
重定向出问题了
if exist autorun.inf goto exist
>autorun.inf echo.
:exist
>>autorun.inf echo [autorun]
>>autorun.inf echo icon=%1
pause
第 3 楼
发表于 2008-03-03 16:18 · 中国 重庆 电信
初级用户
★
积分 34
发帖 14
注册 2007-12-13 18:21
18年会员
UID 105563
性别 男
状态 离线
Originally posted by HAT at 2008-3-3 03:10 PM:
重定向出问题了
if exist autorun.inf goto exist
>autorun.inf echo.
:exist
>>autorun.inf echo
>>autorun.inf echo icon=%1
pause
还是不行啊。文件拖上去还是不运行。
第 4 楼
发表于 2008-03-03 21:10 · 中国 台湾 中华电信(HiNet)数据中心
初级用户
★
积分 109
发帖 30
注册 2007-09-05 14:27
18年会员
UID 96621
性别 男
状态 离线
在最前面加上一行
cd /d "%~dp1"
如果 %1 沒有空格,不可以有 =
第 5 楼
发表于 2008-03-03 23:24 · 中国 重庆 电信
初级用户
★
积分 34
发帖 14
注册 2007-12-13 18:21
18年会员
UID 105563
性别 男
状态 离线
我自己发现如果重定向的文件是有具体路径的话(例子里就是可以把原来的autorun.inf改成l:\autorun.inf等等)就不会出问题。
现在又细看了一下mkd兄的方法,原因找到了,原来在其它文件拖到批处理文件上运行的时候,cmd中的运行目录是在C:\Documents and Settings\Administrator的默认目录下运行的,而不指定绝对路径的autorun.inf也是生成在C:\Documents and Settings\Administrator下的(后来去检查了一下,果然有一个autorun.inf在)。
但是mkd的这句不懂啊:”如果 %1 沒有空格,不可以有 =“ 是什么意思呢?
第 6 楼
发表于 2008-03-04 23:08 · 中国 台湾 中华电信(HiNet)数据中心
初级用户
★
积分 109
发帖 30
注册 2007-09-05 14:27
18年会员
UID 96621
性别 男
状态 离线
aa.bat
@echo off
echo %cmdcmdline%
echo.%1
echo.%2
echo.%3
echo.%4
echo.%5
echo.%6
echo.END
pause >nul
將x,y.txt x;y.txt x=y.txt 拖到aa.bat
cmd /c ""C:\aa.bat" C:\x,y.txt C:\x;y.txt C:\x=y.txt"
C:\x
y.txt
C:\x
y.txt
C:\x
y.txt
END
將x ,y.txt x ;y.txt x =y.txt 拖到aa.bat
cmd /c ""C:\aa.bat" "C:\x ,y.txt" "C:\x ;y.txt" "C:\x =y.txt""
"C:\x ,y.txt"
"C:\x ;y.txt"
"C:\x =y.txt"
END
將C:\A B\x,y.txt C:\A B\x;y.txt C:\A B\x=y.txt 拖到C:\A B\aa.bat
cmd /c ""C:\A B\aa.bat" "C:\A B\x,y.txt" "C:\A B\x;y.txt" "C:\A B\x=y.txt""
"C:\A B\x,y.txt"
"C:\A B\x;y.txt"
"C:\A B\x=y.txt"
END
http://www.cn-dos.net/forum/viewthread.php?tid=31223
论坛跳转: