如何在由快捷方式启动的程序中获取(.lnk)快捷方式文件路径? [英] How to get the (.lnk) shortcut filepath in a program which started by the shortcut?

查看:50
本文介绍了如何在由快捷方式启动的程序中获取(.lnk)快捷方式文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个打开 *.postfix 文件的 c# 程序.

I have a c# program which open *.postfix file.

如果用户运行指向我的文件类型的 (.lnk) 快捷方式,我的程序将打开目标.

If a user runs a (.lnk)shortcut which points to my type of file, my program will open the target.

那么,我的程序怎么知道它是由(.lnk)快捷方式启动的(并获取它的文件路径)?

So, how could my program know it is started by a (.lnk)shortcut (and get it's file path)?

在某些情况下,我需要替换 .lnk 文件.

In some circumstances,i need to replace the .lnk file.

谢谢!

已编辑首先,感谢回答我问题的人.

Edited First, thanks to guys who answered my question.

按照@Anders 的回答,我发现我的问题就出在这里.

By following @Anders answer, i find out my problem lays here.

我对 Windows 注册表进行了一些更改,因此浏览器知道向某些程序抛出自定义协议字符串.

I made some changes to windows registry, so browser knows to throw customized protocol string to certain program.

这样的事情..

[互联网快捷方式]URL=myProtocol://abcdefg.....

[InternetShortcut] URL=myProtocol://abcdefg.....

这也许就是我丢失 lpTitle 的原因.:(

That's maybe why i lost lpTitle. :(

我要试试这种方式:每当我的程序调用时,当然用 %1 提供,程序检查当前打开的资源管理器(窗口),并尝试使用 IWebBrowserApp 获取它的当前路径.当然有了那个路径和桌面,扫描分析 *.lnk 来决定替换哪个.

I'm going to try this way: Whenever my program invoked, of course fed with %1, program checks current opened explorer(Window), and try to get it's current path with IWebBrowserApp. With that path and desktop of course, scan and analyze *.lnk to determine which one to replace.

我认为这可能会奏效,但不确定.我会尝试.继续

I think this will probably work, but not be sure. I will try. continued

推荐答案

在本机代码中,您可以调用 GetStartupInfo,如果 STARTF_TITLEISLINKNAME 位在 STARTUPINFO.dwFlags 中设置,则路径.lnk 在 STARTUPINFO.lpTitle 中.我不知道是否有 .NET 方式来获取此信息,您可能必须 P/Invoke ...

In native code you can call GetStartupInfo, if the STARTF_TITLEISLINKNAME bit is set in STARTUPINFO.dwFlags then the path to the .lnk is in STARTUPINFO.lpTitle. I don't know if there is a .NET way to get this info, you probably have to P/Invoke...

这篇关于如何在由快捷方式启动的程序中获取(.lnk)快捷方式文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆