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#设置开机启动的方法
最新推荐文章于 2024-08-31 11:50:22 发布