gpt4 book ai didi

c# - 如何获取应用程序快捷方式的当前目录路径

转载 作者:太空狗 更新时间:2023-10-29 21:09:31 25 4
gpt4 key购买 nike

我想获取当前目录路径,但不是应用程序位置,而是它的快捷方式位置。

我尝试了这些,但它们返回了应用程序的位置。

Directory.GetCurrentDirectory();
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);

最佳答案

根据 MSDN 中的进程 API 引用,给定进程的进程 STARTUPINFO 结构在 title 成员中包含有关快捷方式 .lnk 文件的信息。在这种情况下设置的 dwFlags 结构成员中有一个标志 - 所以看起来这并不总是设置(我猜你是否直接运行了 exe)

来自 MSDN:

STARTF_TITLEISLINKNAME: 0x00000800

The lpTitle member contains the path of the shortcut file (.lnk) that the user invoked to start this process. This is typically set by the shell when a .lnk file pointing to the launched application is invoked. Most applications will not need to set this value. This flag cannot be used with STARTF_TITLEISAPPID.

Reference here .

关于c# - 如何获取应用程序快捷方式的当前目录路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15758941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com