2

我正在使用 WshShell VS2010 .Net 4 和 ant 创建一个快捷方式,以便能够创建一个引用 AccessRuntinme 然后是我们的应用程序的目标路径。这是我到目前为止没有错误的,直到我运行程序并单击按钮。

 private void CreateShortCut64()
    {
        object shDesktop = (object)"Desktop";
        WshShell shell = new WshShell();
        string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\LinkName.lnk";
        IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
        string targetPath64 = "\"C:\\Program Files (x86)\\Microsoft Office\\Office12\\MSACCESS.EXE\" \"C:\\Program Files (x86)\\My Program\\Prog.accdr\"";
        shortcut.Description = "Program";
        shortcut.Hotkey = "Ctrl+Shift+A";
        shortcut.TargetPath = targetPath64;
        shortcut.IconLocation = "c:\\Program Files (x86)\\My Program\\" + @"\Prog.ico";
        shortcut.Save();
    }

如果我省略了对 Access Runtime 的引用并且只将我的程序作为目标,那么上面的示例可以正常工作,但是我希望在通过 Windows 编辑目标时可以正常工作的目标中同时包含这两个。

任何帮助都感激不尽。

4

1 回答 1

2

I suspect that it is because you are not setting MS Access to run-time mode:

"C:\Program Files (x86)\Microsoft Office\Office12\MSACCESS.EXE" /runtime "C:\Program Files (x86)\My Program\Prog.accdr"

Edit re comments

shortcut.TargetPath = "\"C:\\Program Files (x86)\\Microsoft Office\\Office12\\MSACCESS.EXE\";
shortcut.Arguments = "\"C:\\Program Files (x86)\\My Program\\Prog.accdr\" /runtime";

I tested with MS Access 2010 x64 installed, so the path names are different, otherwise the code is pretty similar to the OP.

object shDesktop = (object)"Desktop";
WshShell shell = new WshShell();
string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\LinkName.lnk";
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.Description = "Program";
shortcut.Hotkey = "Ctrl+Shift+A";
shortcut.TargetPath = "\"C:\\Program Files\\Microsoft Office\\Office14\\MSACCESS.EXE\"";
shortcut.Arguments = "\"C:\\Program Files (x86)\\My Program\\Prog.accdr\"  /runtime";
shortcut.IconLocation = "c:\\Program Files (x86)\\Abtrac\\" + @"\Prog.ico";
shortcut.Save();
于 2012-07-23T21:47:57.150 回答