public void SetSetupWindowOpenRun(bool _bool)
{
if (_bool)
{
string setupPath = this.GetType().Assembly.Location;
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + "aaaaaaaaaaaa" + ".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 = "aaaaaaaaaaaa";//描述
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;
}
}
else
{
System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + "aaaaaaaaaaaa" + ".lnk");
}
}
C#设置开机启动的方法
最新推荐文章于 2025-03-08 00:44:18 发布
本文介绍了一种使用C#实现程序开机自启动的方法。通过创建快捷方式并将其放置到Windows系统的启动文件夹中,可以实现在系统启动时自动运行指定的应用程序。文中详细展示了如何编写代码来处理这一过程,包括异常处理。
1038

被折叠的 条评论
为什么被折叠?



