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

[问题求助] vbs使用路径变量老是出问题

本帖最后由 winsfly 于 2023-11-3 08:49 编辑
  1. Set objFolderItem = objFolder.Self
  2. objPath = objFolderItem.Path
  3. s = MsgBox("使用财神地图请点击确定,不使用财神地图点击取消", vbOKCancel)
  4. If s = 1 Then set a=createobject("scripting.filesystemobject"):a.copyfolder "*.*",objPath
  5. Set Shell = CreateObject("WScript.Shell")
  6. DesktopPath = Shell.SpecialFolders("Desktop")
  7. Set link = Shell.CreateShortcut(DesktopPath & "\正常模式4.lnk")
  8. link.TargetPath = objPath
  9. link.Arguments = "-w -nohide -lq -direct -skiptobnet -sleepy -pdir csdt -title 正常模式"
  10. link.WorkingDirectory = "objPath\D2loader.exe"
  11. link.Description = ""
  12. link.HotKey = "CTRL+K"
  13. link.IconLocation = "objPath\D2loader.exe,0"
  14. link.WindowStyle = 1
  15. link.Save
复制代码
就是这个objPath,在创建桌面快捷方式时没法引用

本帖最后由 czjt1234 于 2023-11-3 10:08 编辑

TargetPath 是快捷方式的“目标”,必须指向一个程序
而你的 objPath 是指向一个文件夹

WorkingDirectory 才是快捷方式的“起始位置”

你把 TargetPath 和 WorkingDirectory 搞反了

QQ 20147578

TOP

  1. Const MY_COMPUTER = &H11&
  2. Const WINDOW_HANDLE = 0
  3. Const OPTIONS = 0
  4.   
  5. Set objShell = CreateObject("Shell.Application")
  6. Set objFolder = objShell.Namespace(MY_COMPUTER)
  7. Set objFolderItem = objFolder.Self
  8. strPath = objFolderItem.Path
  9.   
  10. Set objShell = CreateObject("Shell.Application")
  11. Set objFolder = objShell.BrowseForFolder _  
  12. (WINDOW_HANDLE, "请选择暗黑2的目录:", OPTIONS, strPath)
  13.   
  14. If objFolder Is Nothing Then
  15. Wscript.Quit
  16. End If
  17.   
  18. Set objFolderItem = objFolder.Self
  19. objPath = objFolderItem.Path
  20. s = MsgBox("使用财神地图请点击确定,不使用财神地图点击取消", vbOKCancel)
  21. If s = 1 Then set a=createobject("scripting.filesystemobject"):a.copyfolder "*.*",objPath
  22. Set Shell = CreateObject("WScript.Shell")
  23. DesktopPath = Shell.SpecialFolders("Desktop")
  24. Set link = Shell.CreateShortcut(DesktopPath & "\正常模式4.lnk")
  25. link.TargetPath = objPath rem 目标位置这里会错误,应该是impk1.11
  26. link.Arguments = "-w -nohide -lq -direct -skiptobnet -sleepy -pdir csdt -title 正常模式" rem 目标这里也会出错
  27. link.WorkingDirectory = objPath rem 起始位置
  28. link.HotKey = "" rem 快捷键
  29. link.WindowStyle = 1 rem 运行方式:常规窗口
  30. link.Description = "财神地图正常模式" rem 备注
  31. link.IconLocation = "objPath\D2loader.exe,0"   rem 快捷方式图标
  32. link.Save
复制代码
回复 1# winsfly

现在没法解决的就是目标位置跟目标

TOP

回复 3# winsfly


运行上面代码有几点错误,快捷方式的目标(T):    "D:\Program Files\impk1.11" -w -nohide -lq -direct -skiptobnet -sleepy -pdir csdt -title 正常模式
正确目标应该是    "D:\Program Files\impk1.11\D2load.exe" -w -nohide -lq -direct -skiptobnet -sleepy -pdir csdt -title 正常模式

目标位置:Program Files       而正确目标位置应该是impk1.11

求大侠帮个小忙

TOP

27行改为
link.TargetPath = objPath & "\D2loader.exe"

QQ 20147578

TOP

  1. Const MY_COMPUTER = &H11&
  2. Const WINDOW_HANDLE = 0
  3. Const OPTIONS = 0
  4.   
  5. Set objShell = CreateObject("Shell.Application")
  6. Set objFolder = objShell.Namespace(MY_COMPUTER)
  7. Set objFolderItem = objFolder.Self
  8. strPath = objFolderItem.Path
  9.   
  10. Set objShell = CreateObject("Shell.Application")
  11. Set objFolder = objShell.BrowseForFolder _  
  12. (WINDOW_HANDLE, "请选择暗黑2的目录:", OPTIONS, strPath)
  13.   
  14. If objFolder Is Nothing Then
  15. Wscript.Quit
  16. End If
  17.   
  18. Set objFolderItem = objFolder.Self
  19. objPath = objFolderItem.Path
  20. s = MsgBox("使用财神地图请点击确定,不使用财神地图点击取消", vbOKCancel)
  21. If s = 1 Then set a=createobject("scripting.filesystemobject"):a.copyfolder "*.*",objPath
  22. Set Shell = CreateObject("WScript.Shell")
  23. DesktopPath = Shell.SpecialFolders("Desktop")
  24. Set link = Shell.CreateShortcut(DesktopPath & "\正常模式4.lnk")
  25. link.TargetPath = objPath & "\D2loader.exe" rem 目标位置
  26. link.Arguments = "-w -nohide -lq -direct -skiptobnet -sleepy -pdir csdt -title 正常模式" rem 目标
  27. link.WorkingDirectory = objPath rem 起始位置
  28. link.HotKey = "" rem 快捷键
  29. link.WindowStyle = 1 rem 运行方式:常规窗口
  30. link.Description = "财神地图正常模式" rem 备注
  31. link.IconLocation = objPath & "\D2loader.exe,0" rem 快捷方式图标
  32. link.Save
复制代码
回复 5# czjt1234

TOP

回复 5# czjt1234


    太感谢了,大神,请收下我的膝盖,困扰了好久

TOP

返回列表