[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 怎样创建批处理文件自身的快捷方式?

如题,我用网上找到的代码
  1. echo [InternetShortcut] >> %~p0\shortcut.url
  2. echo URL="%~f0" >> %~p0\shortcut.url
  3. echo IconIndex=29 >>shortcut.url
  4. echo IconFile=C:\windows\system32\shell32.dll >>shortcut.url
复制代码
不能运行,总是出现下图的错误提示!
[attach]1549[/attach]
麻烦大侠帮忙想想,有没有别的好方法了!

多谢大侠了!

%~p0是批处理自身所在路径,若其中有空格必须用""闭合。
另,是生成在当前目录,%~p0可以不要。
去掉试下:
  1. echo [InternetShortcut]> shortcut.url
  2. echo URL="%~f0">>shortcut.url
  3. echo IconIndex=29>>shortcut.url
  4. echo IconFile=C:\windows\system32\shell32.dll>>shortcut.url
复制代码
心绪平和,眼藏静谧。

TOP

还是不行,问题一样,还是提示上面的错误!

TOP

我这里测试正常。
测试信息:
  1. D:\>type a.bat
  2. echo [InternetShortcut]> shortcut.url
  3. echo URL="%~f0">>shortcut.url
  4. echo IconIndex=29>>shortcut.url
  5. echo IconFile=C:\windows\system32\shell32.dll>>shortcut.url
  6. pause
  7. D:\>a.bat
  8. D:\>echo [InternetShortcut] 1>shortcut.url
  9. D:\>echo URL="D:\a.bat" 1>>shortcut.url
  10. D:\>echo IconIndex=29 1>>shortcut.url
  11. D:\>echo IconFile=C:\windows\system32\shell32.dll 1>>shortcut.url
  12. D:\>pause
  13. 请按任意键继续. . .
  14. D:\>type shortcut.url
  15. [InternetShortcut]
  16. URL="D:\a.bat"
  17. IconIndex=29
  18. IconFile=C:\windows\system32\shell32.dll
  19. D:\>shortcut.url
  20. D:\>
复制代码
shortcut.url:
  1. D:\>echo [InternetShortcut] 1>shortcut.url
  2. D:\>echo URL="D:\a.bat" 1>>shortcut.url
  3. D:\>echo IconIndex=29 1>>shortcut.url
  4. D:\>echo IconFile=C:\windows\system32\shell32.dll 1>>shortcut.url
  5. D:\>pause
  6. 请按任意键继续. . .
复制代码
心绪平和,眼藏静谧。

TOP

URL快捷方式尽量少用于非URL,毕竟不是通用快捷方式.lnk,有时可能会出现意料之外的错误
用vbs生成.lnk快捷方式:
  1. set ws = WScript.CreateObject("WScript.Shell")
  2. strDesktop = ws.SpecialFolders("Desktop")
  3. set oShellLink = ws.CreateShortcut(strDesktop & "\a.lnk")
  4. oShellLink.TargetPath = "C:\test\a.bat"
  5. oShellLink.IconLocation = "C:\windows\system32\shell32.dll, 29"
  6. oShellLink.WorkingDirectory = strDesktop
  7. oShellLink.Save
复制代码
命令行参考:hh.exe ntcmds.chm::/ntcmds.htm
求助者请拿出诚心,别人才愿意奉献热心!
把查看手册形成条件反射!

TOP

返回列表