使用C#引导到任务栏
我搜索了同一主题,并找到了解决方案。但是问题是名称空间属性给出了例外。我已经尝试了此代码:
public bool PinUnpinTaskbar(string filePath, bool pin)
{
if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);
int MAX_PATH = 255;
var actionIndex = pin ? 5386 : 5387; // 5386 is the DLL index for"Pin to Tas&kbar", ref. http://www.win7dll.info/shell32_dll.html
//uncomment the following line to pin to start instead
//actionIndex = pin ? 51201 : 51394;
StringBuilder szPinToStartLocalized = new StringBuilder(MAX_PATH);
IntPtr hShell32 = LoadLibrary("Shell32.dll");
LoadString(hShell32, (uint)actionIndex, szPinToStartLocalized, MAX_PATH);
string localizedVerb = szPinToStartLocalized.ToString();
string path = Path.GetDirectoryName(filePath);
string fileName = Path.GetFileName(filePath);
// create the shell application object
//var shell = new Shell32.Shell();
dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
dynamic directory = shellApplication.NameSpace(path);
dynamic link = directory.ParseName(fileName);
dynamic verbs = link.Verbs();
for (int i = 0; i < verbs.Count(); i++)
{
dynamic verb = verbs.Item(i);
if (verb.Name.Equals(localizedVerb))
{
verb.DoIt();
return true;
}
}
return false;
}
但是问题在于ShellApplication.namespace(路径)。它找不到这样的属性/方法。我对此没有太多的想法。因此,将不胜感激。
I have searched for this same topic and I found the solution. But the problem is the NameSpace property is giving exception. I have tried with this code :
public bool PinUnpinTaskbar(string filePath, bool pin)
{
if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);
int MAX_PATH = 255;
var actionIndex = pin ? 5386 : 5387; // 5386 is the DLL index for"Pin to Tas&kbar", ref. http://www.win7dll.info/shell32_dll.html
//uncomment the following line to pin to start instead
//actionIndex = pin ? 51201 : 51394;
StringBuilder szPinToStartLocalized = new StringBuilder(MAX_PATH);
IntPtr hShell32 = LoadLibrary("Shell32.dll");
LoadString(hShell32, (uint)actionIndex, szPinToStartLocalized, MAX_PATH);
string localizedVerb = szPinToStartLocalized.ToString();
string path = Path.GetDirectoryName(filePath);
string fileName = Path.GetFileName(filePath);
// create the shell application object
//var shell = new Shell32.Shell();
dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
dynamic directory = shellApplication.NameSpace(path);
dynamic link = directory.ParseName(fileName);
dynamic verbs = link.Verbs();
for (int i = 0; i < verbs.Count(); i++)
{
dynamic verb = verbs.Item(i);
if (verb.Name.Equals(localizedVerb))
{
verb.DoIt();
return true;
}
}
return false;
}
But the problem is with shellApplication.Namespace(path) here. It can not find such property/Method. I don't have too much idea on this. So, any kind of help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WRT W10:我唯一能够对此有意义的方法是;
由用户决定“销钉到任务栏”。但是,您必须设置最终发生的参考。也就是说,如果您希望您的应用程序组合应用程序和快速启动图标。否则,每次程序启动时,都会在任务栏中创建第二个图标。
当用户手动将应用程序固定到任务栏时,将在快速启动文件夹中创建第二个快捷键。但是,这个降落在... \ Quick启动\用户固定\任务栏中。不要问我为什么这一切都需要在... \ roaming \ Microsoft \ Internet Explorer ...疯狂!
干杯。
WRT W10: The only way I have ever been able to make any sense of this is;
It's up to user to "pin to taskbar". However, you must setup a reference for when it eventually happens. That is, if you want your app to combine the app and quick launch icons. Otherwise, a second icon will be created in the taskbar every time the program starts.
When the user manually pins app to taskbar, a second shortcut is created in the quick launch folder. However, this one lands in ...\Quick Launch\User Pinned\TaskBar. Do not ask me why this all needs to happen in ...\Roaming\Microsoft\Internet Explorer... MADNESS!
Cheers.