ManageStartUpApps:C#操作注册表来读取和修改开机启动项

同样,还是需要操作注册表的,具体如何操作就不用我多说了.

【网通】点击这里下载全部源程序    【电信、网通】点击这里下载源程序

【下载说明】
1、单击上面这个地址,打开下载页面。
2、点普通下载--等待30秒--点“下载”按钮--保存

ManageStartUpApps:C#操作注册表来读取和修改开机启动项_第1张图片

主要源程序:

/*
 * Created by SharpDevelop.
 * User: PJ
 * Date: 2012-7-13
 * Time: 16:03
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

using Microsoft.Win32;

namespace ManageStartUpApps
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			LoadStartUpApps();
		}
		
		void LoadStartUpApps()
		{
			listView1.Items.Clear();
			listView1.Columns.Clear();
			
			RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
			
			try
			{
				listView1.Columns.Add("Name");
				listView1.Columns[0].Width=100;
				listView1.Columns.Add("Path");
				listView1.Columns[1].Width=listView1.Width-listView1.Columns[0].Width;
				foreach(string item in pregkey.GetValueNames())
				{
					if(item.Trim()!="")
					{
						ListViewItem lvi=listView1.Items.Add(item);
						lvi.SubItems.Add(pregkey.GetValue(item).ToString());
					}
				}
			}
			catch(Exception e)
			{
				MessageBox.Show(e.Message.ToString(),"Exception");
			}
			finally
			{
				pregkey.Close();
			}
		}
		
		void BtnRefreshClick(object sender, EventArgs e)
		{
			LoadStartUpApps();
		}
		
		void BtnDeleteClick(object sender, EventArgs e)
		{
			string appName = listView1.SelectedItems[0].Text;
			RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run",true);
			
			try
			{
				pregkey.DeleteValue(appName);
			}
			catch(Exception E)
			{
				MessageBox.Show(E.Message.ToString());
			}
			finally
			{
				pregkey.Close();
			}
			
			LoadStartUpApps();
		}
		
		void BtnAddClick(object sender, EventArgs e)
		{
			AppForm af = new AppForm();
			if(af.ShowDialog() == DialogResult.OK)
			{
				string appName = AppForm.appName;
				string appPath = AppForm.appPath;
				
				RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run",true);
				
				try
				{
					pregkey.SetValue(appName,appPath,RegistryValueKind.String);
				}
				catch(Exception E)
				{
					MessageBox.Show(E.Message.ToString(),"Exception");
				}
				finally
				{
					pregkey.Close();
				}
				
				LoadStartUpApps();
			}
		}
	}
}

【更多文章】

  1. [译]用C#检测你的打印机是否连接
  2. [原]《The C Programming Language》电子书下载
  3. [原]使用Excel的VBA来读取和修改bmp位图像素数据
  4. [原]GetAlpha:C#实现获取网页验证码图片,并识别出其中的字母
  5. [原]Cls_Ini.cls:VB写的操作ini配置文件的类
  6. [译]C#控制计算机的并口LPT
  7. [原]QQHelper:QQ大家来找茬 辅助工具 外挂
  8. [译]在C# .NET2.0实现单实例应用程序
  9. [译]在C# .NET2.0实现单实例应用程序
  10. [原]IniFile.cs:C#来操作ini配置文件

你可能感兴趣的:(ManageStartUpApps:C#操作注册表来读取和修改开机启动项)