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

[问题求助] [已解决] VBS中创建带有unicode字符的快捷方式应如何改?

本帖最后由 adan1 于 2017-1-27 19:41 编辑

由于脚本带有unciode字符,VBS文件必须保存为unicode编码,跟目标程序于同一目录下,这个目录也是带有unicode字符的。
就这样运行的话,第6行就报错了。
  1. rootPath=createobject("Scripting.FileSystemObject").GetFolder(".").Path
  2. currentPath=rootPath & "\"
  3. set WshShell=WScript.CreateObject("WScript.Shell")
  4. set oShellLink=WshShell.CreateShortcut(currentPath & "イブニクル・ランス版.lnk")
  5. oShellLink.TargetPath=currentPath & "EvenicleRance.exe"
  6. oShellLink.Arguments=""
  7. oShellLink.WorkingDirectory=currentPath
  8. 'oShellLink.Hotkey=""
  9. oShellLink.WindowStyle=1
  10. oShellLink.Description=""
  11. oShellLink.Save
复制代码

本帖最后由 adan1 于 2017-1-23 21:38 编辑

回复 2# yu2n


    感谢回答,思路上是可以的。不过在我这边用上面代码执行,同样报第6行的错,估计是目录带有unicode字符造成的。我另外测试,如果targetPath指向的文件名也带有unicode字符,依然会报错。
我感觉不解决根本的字符转换问题,会是处处碰壁。

TOP

回复 4# yu2n

测试平台 Win7x86
1. 目标文件所在目录带有unicode字符,比如:・
    使用2L代码,执行后提示错误:

2. 目标文件名带有unicode字符,比如:・
    目录没有带unicode字符,使用2L代码并修改targetPath指向带有unicode字符名的文件,执行后提示错误:

TOP

回复 6# yu2n

没怎么弄过INF,常见于驱动那边,看上去会给系统绑定些什么的。。。

TOP

回复 7# CommandBatCmd


嗯,很同意历史遗留的编码问题,以前相对封闭的空间使用区域性编码,而现在全世界互联造成各种冲突。Windows上至今升级到WIN10好像仍用这样的编码方式,写个批处理换别的语言平台就显示乱码了。
你提出的只使用系统默认编码之内的字符,做法是正确的,不过我觉得这应该是真正软件开发者所要考虑的,而我只是事后为其做些小事情,在不破坏原有程序的前提下。前几次我遇到过带unicode字符的快捷方式,那时是使用形状相近的非unicode字符替换 临时解决掉,而现在连目录也带有unicode字符,现有的脚本无法可施。

TOP

回复 8# 老刘1号

。。。压缩包的方式算是写死了吧,而且还要求自带解压程序,这曲线想想都麻烦

TOP

我google了几篇国外求助贴,算是搞起来了。一开始是用VBS去执行powershell的,后来才想起可以直接VBS。。。
  1. set fso = CreateObject("Scripting.FileSystemObject")
  2. rootPath = fso.GetFolder(".").Path
  3. set objShell = CreateObject("shell.application")
  4. currentPath = rootPath & "\"
  5. set objFolder = objShell.NameSpace(currentPath)
  6. lnkname = "イブニクル・ランス版.lnk"
  7. set objFolderItem = objFolder.ParseName(lnkname)
  8. if objFolderItem Is Nothing then
  9.     fso.CreateTextFile currentPath & lnkname, true
  10.     set objFolderItem = objFolder.ParseName(lnkname)
  11. end if
  12. set objShellLink = objFolderItem.GetLink
  13. objShellLink.Path = currentPath & "Evenicle・Rance.exe"
  14. objShellLink.Arguments = ""
  15. objShellLink.WorkingDirectory = currentPath
  16. objShellLink.Hotkey = 0
  17. objShellLink.ShowCommand = 1
  18. objShellLink.Description = ""
  19. objShellLink.SetIconLocation currentPath & "Evenicle・Rance.exe", 0
  20. objShellLink.Save()
复制代码
暂时先这样,看看还有没需要改正的。
1

评分人数

    • yu2n: 使用shell.application创建快捷方式,不错。 ...技术 + 1

TOP

今天又是带有unicode的,而且是多个,顺应修改下复用。
  1. set objShell = CreateObject("shell.application")
  2. set fso = CreateObject("Scripting.FileSystemObject")
  3. Function createLink(path, linkName)
  4.     set objFolder = objShell.NameSpace(path)
  5.     set objFolderItem = objFolder.ParseName(linkName)
  6.     if objFolderItem Is Nothing then
  7.         fso.CreateTextFile path & linkName, true
  8.         set objFolderItem = objFolder.ParseName(linkName)
  9.     end if
  10.     set createLink = objFolderItem.GetLink
  11. End Function
  12. rootPath = fso.GetFolder(".").Path
  13. Function currentPath(path)
  14.     if isNull(path) then
  15.         currentPath = rootPath
  16.     elseif path = "" then
  17.         currentPath = rootPath & "\"
  18.     elseif path = "\" then               '特殊
  19.         currentPath = rootPath
  20.     elseif left(path, 1) = "\" then      '特殊
  21.         currentPath = rootPath & path
  22.     elseif right(path, 1) = "\" then
  23.         currentPath = rootPath & "\" & path
  24.     else
  25.         currentPath = rootPath & "\" & path & "\"
  26.     end if
  27. End Function
  28. set objShellLink = createLink(currentPath(""), "手垢塗れの天使.lnk")
  29. objShellLink.Path = currentPath("") & "angel.exe"
  30. objShellLink.Arguments = ""
  31. objShellLink.WorkingDirectory = currentPath("\")
  32. objShellLink.Hotkey = 0
  33. objShellLink.ShowCommand = 1
  34. objShellLink.Description = ""
  35. objShellLink.SetIconLocation currentPath("") & "angel.exe", 0
  36. objShellLink.Save()
  37. set objShellLink = createLink(currentPath(""), "手垢塗れの天使の詳細設定.lnk")
  38. objShellLink.Path = currentPath("") & "angel.exe"
  39. objShellLink.Arguments = "-userconf"
  40. objShellLink.WorkingDirectory = currentPath("\")
  41. objShellLink.Hotkey = 0
  42. objShellLink.ShowCommand = 1
  43. objShellLink.Description = ""
  44. 'objShellLink.SetIconLocation currentPath("") & ".exe.ico.dll", 0
  45. objShellLink.Save()
  46. set objShellLink = createLink(currentPath(""), "手垢塗れの天使のファイル破損チェック.lnk")
  47. objShellLink.Path = currentPath("data") & "ファイル破損チェックツール.exe"
  48. objShellLink.Arguments = ""
  49. objShellLink.WorkingDirectory = currentPath("\")
  50. objShellLink.Hotkey = 0
  51. objShellLink.ShowCommand = 1
  52. objShellLink.Description = ""
  53. 'objShellLink.SetIconLocation currentPath("") & ".exe.ico.dll", 0
  54. objShellLink.Save()
复制代码

TOP

回复 14# yu2n

不错

TOP

返回列表