通过VBScript的快捷目标路径

时间:2018-08-25 00:32:17

标签: 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版本。尝试获取正确数量的双引号,以便可以映射快捷方式。

1 个答案:

答案 0 :(得分:0)

尽管.MDB扩展名可能与MsAccess关联,但我知道您希望快捷方式明确使用已安装的MsAccess.exe,以避免在用户将其更改为其他应用程序时遇到麻烦。

在创建这样的快捷方式时,您需要为不同的属性填写正确的值。

快捷方式 TargetPath 应该为"C:\Program Files\Microsoft Office 15\Root\Office 15\MSACCESS.EXE" 参数的快捷方式应为"\\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