首页 > 解决方案 > 通过 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 版本而异。尝试获取正确数量的双引号,以便可以映射快捷方式。

标签: vbscript

解决方案


尽管该.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

推荐阅读