我正在使用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的引用并且只将My Program作为目标,上面的例子工作正常但是我希望在目标中通过windows编辑目标时工作正常。
非常感谢任何帮助。
答案 0 :(得分:2)
我怀疑是因为你没有将MS Access设置为运行时模式:
"C:\Program Files (x86)\Microsoft Office\Office12\MSACCESS.EXE" /runtime "C:\Program Files (x86)\My Program\Prog.accdr"
编辑重新评论
shortcut.TargetPath = "\"C:\\Program Files (x86)\\Microsoft Office\\Office12\\MSACCESS.EXE\";
shortcut.Arguments = "\"C:\\Program Files (x86)\\My Program\\Prog.accdr\" /runtime";
我安装了MS Access 2010 x64,因此路径名称不同,否则代码与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();