本文实例讲述了c#实现在启动目录创建快捷方式的方法。分享给大家供大家参考。具体如下:
添加引用,选择 com 选项卡并选择 windows script host object model
/// <summary> /// 将文件放到启动文件夹中开机启动 /// </summary> /// <param name="setuppath">启动程序</param> /// <param name="linkname">快捷方式名称</param> /// <param name="description">描述</param> public void setsetupwindowopenrun(string setuppath, string linkname, string description) { string desktop = environment.getfolderpath(environment.specialfolder.startup) + "\\" + linkname + ".lnk"; if (system.io.file.exists(desktop)) system.io.file.delete(desktop); iwshruntimelibrary.wshshell shell; iwshruntimelibrary.iwshshortcut shortcut; try { shell = new iwshruntimelibrary.wshshell(); shortcut = (iwshruntimelibrary.iwshshortcut)shell.createshortcut(desktop); shortcut.targetpath = setuppath;//程序路径 shortcut.arguments = "";//参数 shortcut.description = description;//描述 shortcut.workingdirectory = system.io.path.getdirectoryname(setuppath);//程序所在目录 shortcut.iconlocation = setuppath;//图标 shortcut.windowstyle = 1; shortcut.save(); } catch (exception ex) { system.windows.forms.messagebox.show(ex.message, "友情提示"); } finally { shell = null; shortcut = null; } }
希望本文所述对大家的c#程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论