110,534
社区成员
发帖
与我相关
我的任务
分享
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' 直接调用COM对象
Dim wsh As Object = CreateObject("WScript.Shell")
Dim desk As String = wsh.SpecialFolders("Desktop")
Dim lnk As Object = wsh.CreateShortcut(desk & "\说明2.lnk")
With lnk
.Arguments = "/?" '传递参数
.Description = "我是直接调用COM创建的非托管对象创建的快捷方式!"
.Ic '调用dll资源内的图标,索引在第23个图标,问号帮助
.TargetPath = Application.StartupPath & "\乐博网.txt"
.WindowStyle = 7 '打开窗体的风格,最小化
.WorkingDirectory = Application.StartupPath '工作路径
.Save() '保存快捷方式
End With
End Sub
string desktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);//得到桌面文件夹
//创建桌面快捷方式
if (chkCreateDesktopLnk.Checked == true)
{
if (!File.Exists(desktopPath + "\\程序名称.lnk"))
{
string target = Application.ExecutablePath;
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(desktopPath + "\\程序名称.lnk");
shortcut.TargetPath = target;
shortcut.Arguments = "";// 参数
shortcut.Description = "程序描述信息";
shortcut.WorkingDirectory = Application.StartupPath;//程序所在文件夹,在快捷方式图标点击右键可以看到此属性
shortcut.IconLocation = target + ",0";//图标
//shortcut.Hotkey = "";//热键CTRL+SHIFT+Z
shortcut.WindowStyle = 1;
shortcut.Save();
}
}
else
{
if (File.Exists(desktopPath + "\\程序名称.lnk"))
File.Delete(desktopPath + "\\程序名称.lnk");
}
// 直接调用COM对象
{
object wsh = Interaction.CreateObject("WScript.Shell");
string desk = wsh.SpecialFolders("Desktop");
object lnk = wsh.CreateShortcut(desk + "\\说明2.lnk");
var _with1 = lnk;
_with1.Arguments = "/?";
//传递参数
_with1.Description = "我是直接调用COM创建的非托管对象创建的快捷方式!";
_with1.Ic();
//调用dll资源内的图标,索引在第23个图标,问号帮助
_with1.TargetPath = Application.StartupPath + "\\乐博网.txt";
_with1.WindowStyle = 7;
//打开窗体的风格,最小化
_with1.WorkingDirectory = Application.StartupPath;
//工作路径
_with1.Save();
//保存快捷方式
}
VB.NET转C#