在c#中获取启动快捷方式

发布于 2024-08-26 10:42:10 字数 410 浏览 10 评论 0原文

假设我有一个可执行文件,当它启动时我想知道它是如何启动的。即我想知道它是通过快捷方式启动还是直接启动。 这样:

string test = Environment.GetCommandLineArgs()[0];

我可以获得可执行文件的路径,但这始终是相同的,即使它是通过快捷方式启动的。

假设我的可执行文件名为 c:\text.exe,我直接启动它,然后 test = 'c:\test.exe' 如果我创建一个快捷方式,即 c:\shortcut.lnk (目标为 c:\test.exe),我希望 test 为“c:\shortcut.exe”,但它是“c:\test.exe”,

我强烈怀疑这一点这是不可能的,因为操作系统处理快捷方式部分,而可执行文件永远看不到差异,但也许有人有一个创造性的想法?

Lets say that I have an executable and when it is started I want to know how it's started. I.e. I would like to know if it is started with a shortcut or directly.
With this:

string test = Environment.GetCommandLineArgs()[0];

I can get the path of the executable, but this is always the same, even if it's started by a shortcut.

Lets say my executable is named c:\text.exe and I start it directly, then test = 'c:\test.exe'
If I create a shortcut i.e. c:\shortcut.lnk (with target c:\test.exe) I want test to be 'c:\shortcut.exe' but it is 'c:\test.exe'

I strongly suspect this to be impossible because the OS handles the shortcut part and the executable never can see the difference, but maybe someone has a creative idea?

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

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

发布评论

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

评论(2

川水往事 2024-09-02 10:42:10

这通常不起作用,但如果您要创建快捷方式,则可以添加命令行参数来识别它。

This won't work in general, but if you are creating the shortcut, you could add a command line parameter to identify it.

め可乐爱微笑 2024-09-02 10:42:10

您的怀疑是正确的,操作系统向您隐藏了机制。

可以获取启动您的进程 , 然而。但这无法帮助您区分是从开始菜单中的链接启动还是从资源管理器窗口中双击启动。

Your suspicions are correct, with the operating system hiding the mechanics from you.

It is possible to get the process that started you, however. this won't help you differentiate whether you were started from a link in the start menu, vs. being doubled clicked on in the explorer window though.

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