%cd%和%~dp0无效的原因,开启cmd命令扩展

迅恒数据中心
%~dp0表示批处理文件所在的路径,如果在bat或vbs或cmd中执行%~dp0无法显示为路径的原因:
没开启cmd命令扩展,只用cmd /e:on开启CMD命令扩展即可,off为关闭

相关bat
@echo off cmd /e:on
(echo Set WshShell=CreateObject("WScript.Shell"^)
echo strDesKtop=WshShell.SpecialFolders("DesKtop"^) '特殊文件夹“桌面”
echo Set oShellLink=WshShell.CreateShortcut(strDesKtop^&"\SecureCRT 8.7.3.lnk"^) '在桌面创建一个快捷方式
echo oShellLink.TargetPath="%~dp0\SecureCRT.exe" '目标
echo oShellLink.WorkingDirectory="%~dp0" '起始位置
echo oShellLink.WindowStyle=1 '1默认窗口,3最大化,7最小化
echo oShellLink.Description = "SecureCRT 8.7.3" '备注
echo oShellLink.Save '保存快捷方式的设置
echo Set oShellLink1=WshShell.CreateShortcut(strDesKtop^&"\SecureFX 8.7.3.lnk"^)
echo oShellLink1.TargetPath="%~dp0\SecureFX.exe"
echo oShellLink1.WorkingDirectory="%~dp0"
echo oShellLink1.WindowStyle=1
echo oShellLink1.Description = "SecureFX 8.7.3"
echo oShellLink1.Save)>makelnk.vbs
makelnk.vbs
del /f /q makelnk.vbs

 

分类:教程帮助 百度收录 必应收录