浏览到exe并创建快捷方式 [英] Browse to exe and create shortcut

查看:91
本文介绍了浏览到exe并创建快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是,只需点击一下按钮,用户就可以选择要创建快捷方式的可执行文件。



例如我们在文件夹c:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\保存,该文件夹中的可执行文件的快捷方式将显示在文件夹c:\shortcuts \



我潜伏了一段时间,发现了一个示例代码在如何创建快捷方式,但我不知道我将如何做,就像我上面解释的那样。



What I desire to do is that in a click of a button the user gets to choose executable file to which he wants to create a shortcut.

For example we have the game Doom 3 in the folder "c:\games\doom3\doom.exe"
He would then pick the executable, click on OK, then in the form click on "save", and a shortcut to that executable would appear in the folder "c:\shortcuts\"

I lurked around for a while and found a sample code in how to create a shortcut but I have no idea how I''m going to do it just like I explained above.

WshShell shell = new WshShell();

            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(@"D:\shotcut.lnk");

            shortcut.TargetPath = Application.ExecutablePath;
            //shortcut.IconLocation = 'Location of  iCon you want to set";

            // add Description of Short cut
            shortcut.Description = "Any Description here ";

            // save it / create
            shortcut.Save();





我也试过这个代码,它会在shortcut.Save上给出一个例外,是因为我使用的是64位系统吗?



先谢谢。



I also tried this code and it would give an exception on "shortcut.Save", is it because I''m using a 64 bit system?

Thanks in advance.

推荐答案

引用:

我没有还没有构建它,这解决了我的一个问题

I haven''t built it yet, that solves one of my questions



继续我的猜测另一个问题是如何猫呃你所描述的用户行为。

在表单中添加一个openFileDialog,然后在你的保存按钮中有类似于


Following on from that I''m guessing the other question is how to cater for the user behaviour you described.
Add an openFileDialog to your form and then in your save button have something similar to

if (this.openFileDialog1.ShowDialog(this) != DialogResult.OK)
	return;
string f = openFileDialog1.FileName;
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(@"C:\shotcut.lnk");
shortcut.TargetPath = f;
shortcut.Description = "Any Description here ";
shortcut.Save();





还有其他方法(例如在openFileDiaglog本身使用方法)所以这不是必然是最好的方式,但它应该给你一个启动器



There are other ways (e.g. using methods on the openFileDiaglog itself) so this is not necessarily the best way but it should give you a starter


嘿史蒂夫,

尝试给它一个真正的绝对路径(到一个真实的文件)



干杯,

Edo
Hey Steve,
Try giving it a real absolute path (to a real file)

Cheers,
Edo


这篇关于浏览到exe并创建快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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