为什么捷径在编程上可以正常工作?

发布于 2025-02-10 00:29:32 字数 774 浏览 1 评论 0原文

我在安装应用程序时使用此代码来对我的应用程序进行快捷方式:

private void CreateShortcut()
{
    object shDesktop = (object)"Desktop";
    WshShell shell = new WshShell();
    string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Baseet.lnk";
    IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
    shortcut.Description = "Baseet Program";
    shortcut.Hotkey = "Ctrl+Shift+N";
    shortcut.TargetPath = Environment.CurrentDirectory + @"\Start_Baseet.exe";
    shortcut.Save();
}

原始应用的作业是打开访问数据库。当它找不到数据库时,向用户显示错误消息,以告诉他们数据库丢失了,并且工作正常。

问题在于,当该快捷方式的原始应用程序正常运行时,前面提到的代码的快捷方式正在显示错误消息“数据库丢失”。怎么可能?

长话短说:我为一个完美工作的应用程序做了一个快捷方式,但是捷径正在显示我在代码中输入的自定义错误消息,因为要求全部存在,因此无法显示。

I use this code to make a shortcut to my app while installing it :

private void CreateShortcut()
{
    object shDesktop = (object)"Desktop";
    WshShell shell = new WshShell();
    string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Baseet.lnk";
    IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
    shortcut.Description = "Baseet Program";
    shortcut.Hotkey = "Ctrl+Shift+N";
    shortcut.TargetPath = Environment.CurrentDirectory + @"\Start_Baseet.exe";
    shortcut.Save();
}

The original app's job is to open an access database. When it can't find the database an error message is shown to the user to tell them that the database is missing and it's working just fine .

The problem is that the shortcut made by previously mentioned code is showing the error message "the database is missing" when at the same time the original app of that shortcut is working just fine. How is that possible ?

Long story short : I made a shortcut to a perfectly working app, but the shortcut is showing a customized error message I put in my code, which can't be shown because the requirements are all there.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羞稚 2025-02-17 00:29:32

尝试设置workingDirectory属性:

shortcut.WorkingDirectory = Environment.CurrentDirectory;

Try to set the WorkingDirectory property:

shortcut.WorkingDirectory = Environment.CurrentDirectory;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文