在桌面WPF C#上创建快捷方式 [英] Create shortcut on desktop WPF C#

查看:211
本文介绍了在桌面WPF C#上创建快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Error:
'System.Windows.Application' does not contain a definition for 'StartupPath'
'System.Windows.Application' does not contain a definition for 'ExecutablePath'





我尝试过:



使用IWshRuntimeLibrary;



var startupFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

var shell = new WshShell();

var shortCutLinkFilePath = System.IO.Path.Combine(startupFolderPath,@\ CreateShortcutSample.lnk);

var windowsApplicationShortcut =(IWshShortcut)shell.CreateS hortcut(shortCutLinkFilePath);

windowsApplicationShortcut.Description =如何为应用程序示例创建简短;

windowsApplicationShortcut.WorkingDirectory = Application.StartupPath;

windowsApplicationShortcut.TargetPath = Application.ExecutablePath;

windowsApplicationShortcut.Save();



What I have tried:

using IWshRuntimeLibrary;

var startupFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var shell = new WshShell();
var shortCutLinkFilePath = System.IO.Path.Combine(startupFolderPath, @"\CreateShortcutSample.lnk");
var windowsApplicationShortcut = (IWshShortcut)shell.CreateShortcut(shortCutLinkFilePath);
windowsApplicationShortcut.Description = "How to create short for application example";
windowsApplicationShortcut.WorkingDirectory = Application.StartupPath;
windowsApplicationShortcut.TargetPath = Application.ExecutablePath;
windowsApplicationShortcut.Save();

推荐答案

这是什么? System.Windows.Forms 习惯? :-)

嗯,你的习惯不能让你免于阅读原始的MSDN文档。



这是完整的和最通用的路径解决方案:

如何找到我的程序目录可执行目录),

如何找到我的程序目录当前目录,特殊文件夹)。



请在下次提问之前,做适当的在文件中搜索。



-SA
What is it? System.Windows.Forms habits? :-)
Well, you habits don't free you from the need to read original MSDN documentation.

Here is the complete and most universal solution for paths:
How to find my programs directory (executable directory),
How to find my programs directory (current directory, "special folders").

Please, next time, before asking questions, do appropriate search in the documentation.

—SA


这篇关于在桌面WPF C#上创建快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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