vbscript - 通过 VBScript 的快捷目标路径
问题描述
我正在尝试使用注册表项和网络共享上的文件位置更正 MS Access 的快捷方式目标路径。
通过注册表访问 MS 的应用路径:
C:\Program Files\Microsoft Office 15\Root\Office 15\MSACCESS.EXE
数据库的网络位置:
\\H00t0000vfsrv03\Share\Folder\Database.MDB
我无法走捷径,给了我
无效的过程调用或参数,800A0005。
代码:
Set WSHShell = CreateObject("WScript.Shell")
ServerPath = Chr(32) & "\\H00t0000vfsrv03\Share\Folder\Database.MDB"
If Not WSHShell Is Nothing Then
DesktopPath = WSHShell.SpecialFolders("Desktop")
InstallRoot = Chr(34) & WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE\") & Chr(34)
TargetName = InstallRoot & ServerPath
WScript.Echo TargetName
CommandName = TargetName
wscript.echo CommandName
Set MyShortcut = WSHShell.CreateShortCut(DesktopPath & "\Shorcut" & ".lnk")
MyShortcut.TargetPath = TargetName
WScript.Echo MyShortcut.TargetPath
MyShortcut.WindowStyle = 1
MyShortcut.Arguments = ""
MyShortcut.Save
Set MyShortcut = Nothing
End If
我已经添加了
shortcut.Targetpath = """C:\Program Files\Microsoft Office 15\Root\Office 15\MSACCESS.EXE"" H00t0000vfsrv03\Share\Folder\Database.MDB"
最后一行不起作用。应用路径可能因 MS Access Office 版本而异。尝试获取正确数量的双引号,以便可以映射快捷方式。
解决方案
尽管该.MDB
扩展可能与 MsAccess 相关联,但我了解您需要一个快捷方式来明确使用已安装的 MsAccess.exe,以避免在用户将其更改为其他应用程序时遇到麻烦。
在创建这样的快捷方式时,您需要为不同的属性填写正确的值。
快捷方式TargetPath应该是"C:\Program Files\Microsoft Office 15\Root\Office 15\MSACCESS.EXE"
快捷方式Arguments 应该是"\\H00t0000vfsrv03\Share\Folder\Database.MDB"
正如您现在所做的那样,您正在尝试TargetPath
将
"C:\PROGRA~2\MICROS~1\Office15\MSACCESS.EXE" \\H00t0000vfsrv03\Share\Folder\Database.MDB
尝试这个
Option Explicit
Dim WSHShell
Set WSHShell = CreateObject("WScript.Shell")
If Not WSHShell Is Nothing Then
Dim ServerPath, DesktopPath, InstallRoot, MyShortcut
ServerPath = Chr(34) & "\\H00t0000vfsrv03\Share\Folder\Database.MDB" & Chr(34)
DesktopPath = WSHShell.SpecialFolders("Desktop")
'get the long path for MSACCESS.EXE
InstallRoot = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE\Path")
'there SHOULD be a backslash at the end, but check anyway
If Right(InstallRoot, 1) <> "\" Then InstallRoot = InstallRoot & "\"
'add "MSACCESS.EXE" to this path and surround with double quotes
InstallRoot = Chr(34) & InstallRoot & "MSACCESS.EXE" & Chr(34)
'create the shortcut on the desktop
Set MyShortcut = WSHShell.CreateShortCut(DesktopPath & "\ShorcutToDatabase" & ".lnk")
MyShortcut.TargetPath = InstallRoot
MyShortcut.WindowStyle = 1
MyShortcut.Arguments = ServerPath
MyShortcut.Save
Set MyShortcut = Nothing
Set WSHShell = Nothing
End if
推荐阅读
- excel - VBA复制列的最后一个非空单元格的值、格式和颜色
- networking - Lora CSMA/CA 管理问题)
- javascript - 如何使用 lodash 扩展对象列表并将其与另一个列表合并
- java - 如何将 application.properties 传递给 dockerfile
- html - Windows 自动更新后 HTML 代码停止打开本地驱动器“.ods”
- r - 我如何计算,在一个会话中总共有多少个项目?
- python - 在 C 中为 Python 创建 C 扩展对象并将其作为参数传递
- flutter - Flutter Listview - 字幕和日期差异问题
- sql - 我正在尝试使用 SQL 邮件以 xlsx 格式发送查询结果,但在 excel 中,它在列和行之间没有得到适当的干扰
- javascript - 如何为我的图片库创建这种悬停效果?