vbscript - 删除快捷方式的脚本不适用于版本号
问题描述
我正在运行一个 vbscript 来删除另一个程序安装的桌面快捷方式,但我遇到的问题是一个快捷方式很顽固
set WshShell = WScript.CreateObject("WScript.Shell" )
strDesktop = WshShell.SpecialFolders("Desktop" )
' delete this shortcut
strShortcut = strDesktop & "\Shortcut Name 2.0.lnk"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strShortcut) Then fso.DeleteFile(strShortcut)
我感觉这与版本号和中间的小数点有关?谁能证实我的怀疑,因为我完全没有线索。
谢谢。
解决方案
您要删除的文件可能不存在,If fso.FileExists(strShortcut) Then
掩盖了这一事实。
您在桌面上看到的快捷方式不必位于您Desktop
使用WshShell.SpecialFolders("Desktop")
.
还有另一个位置,桌面项目作为所有用户桌面目录的扩展存储,但可能需要管理权限才能修改,我不确定,您需要尝试。
因此,除了SpecialFolders("Desktop")
,您还应该考虑SpecialFolders("AllUsersDesktop")
目录。
Set Fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
userDesktop = WshShell.SpecialFolders("Desktop")
publicDesktop = WshShell.SpecialFolders("AllUsersDesktop")
shortcutName = "Shortcut Name 2.0.lnk"
userShortcut = Fso.BuildPath(userDesktop, shortcutName)
publicShortcut = Fso.BuildPath(publicDesktop, shortcutName)
If Fso.FileExists(userShortcut) Then
Fso.DeleteFile userShortcut, True
MsgBox "User shortcut deleted."
End If
If Fso.FileExists(publicShortcut) Then
Fso.DeleteFile publicShortcut, True
MsgBox "Public shortcut deleted."
End If
推荐阅读
- python - Sympy 无法评估涉及伽马函数的无限和
- node.js - 如何在 Node.js 中管理 Cron 作业
- php - 在 Codeigniter Facebook\Facebook 类中找不到 Facebook 登录
- oracle - 在 APEX 应用程序中运行安装脚本时如何为所有者使用替换字符串?
- angular6 - 无法从导航栏导航到 Angular 6 组件
- c# - MS Graph - 401 未经授权看似具有适当的令牌和访问权限
- bash - 将视频从 60 FPS 转换为 25 FPS 而不会减慢它
- node.js - 异步渲染 EJS(先渲染然后数据)
- python - 使用python redis事务时有什么方法可以插入一些python语句?
- reactjs - 将值从组件传递到其他组件的 redux-saga 的最佳方式