如果需要查看更多文章,请微信搜索公众号 csharp编程大全,需要进C#交流群群请加微信z438679770,备注进群, 我邀请你进群! ! !---------------------------------using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using Microsoft.Win32;using System.IO;namespace WindowsFormsApp1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); // Class1.test(); // Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("软件自启动"); String LogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log"); MessageBox.Show(Environment.CurrentDirectory+"\n"+LogPath); //Class1.test(); } private void Form1_Load(object sender, EventArgs e) { AutoStart(); } private void AutoStart(bool isAuto = true, bool showinfo = true) { try { if (isAuto == true) { RegistryKey R_local = Registry.CurrentUser;//RegistryKey R_local = Registry.CurrentUser; RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); R_run.SetValue("应用名称", Application.ExecutablePath); R_run.Close(); R_local.Close(); } else { RegistryKey R_local = Registry.CurrentUser;//RegistryKey R_local = Registry.CurrentUser; RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); R_run.........
C# 软件开机启动
点赞
收藏