C# 设置应用程序开机自启动
主要是通过动态生成vbs脚本,放置在系统自启动目录下,系统开机时会自动执行vbs脚本启动应用程序
开机自启动,自动生成vbs脚本
using (StreamWriter file = new StreamWriter($@"{Environment.GetFolderPath(Environment.SpecialFolder.Startup)}\StartUp.vbs",false,Encoding.Unicode)) { file.WriteLine(@"set ws = wscript.createObject(""wscript.shell"")", Encoding.Unicode); file.WriteLine($@"ws.Run """"""{System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName}"""""", 2, False", Encoding.Unicode); }
关闭开机自启动,删除StartUp.vbs脚本即可
File.Delete($@"{Environment.GetFolderPath(Environment.SpecialFolder.Startup)}\StartUp.vbs");
标签:vbs,C#,StartUp,应用程序,Environment,开机,CSharpTips,自启动 From: https://www.cnblogs.com/axiaoshuye/p/17924341.html