下面是我以前写的一段代码。你可以使用代码的片断,但是不能直接原样使用这些代码。如果希望原样使用这些代码的话,必须得到我本人的书面允许。 using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using Microsoft.Win32;namespace GreensLeaf { /// <summary> /// frmGreensLeafTool 的摘要说明。 /// </summary> public class frmGreensLeafTool : System.Windows.Forms.Form { private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage pgRegRun; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button btnDeleteSelected; private System.Windows.Forms.TextBox txtDebug; private System.Windows.Forms.DataGrid dgRegRun;
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Microsoft.Win32;namespace GreensLeaf
{
/// <summary>
/// frmGreensLeafTool 的摘要说明。
/// </summary>
public class frmGreensLeafTool : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage pgRegRun;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnDeleteSelected;
private System.Windows.Forms.TextBox txtDebug;
private System.Windows.Forms.DataGrid dgRegRun;
private DataTable dtRegRun=new DataTable();
private RegistryKey rkRegRun;
private DataRow drow;
private System.Windows.Forms.Button btnRefresh;
private System.Windows.Forms.StatusBar stbGreensLeaf;
private System.Windows.Forms.Button button1; /// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public frmGreensLeafTool()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); SetDataBinding();
ReloadDataTable();
RefreshGUI();
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.tabControl1 = new System.Windows.Forms.TabControl();
this.pgRegRun = new System.Windows.Forms.TabPage();
this.dgRegRun = new System.Windows.Forms.DataGrid();
this.txtDebug = new System.Windows.Forms.TextBox();
this.btnDeleteSelected = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.stbGreensLeaf = new System.Windows.Forms.StatusBar();
this.btnRefresh = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.tabControl1.SuspendLayout();
this.pgRegRun.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgRegRun)).BeginInit();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.pgRegRun});
this.tabControl1.Location = new System.Drawing.Point(8, 16);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(440, 384);
this.tabControl1.TabIndex = 0;
//
// pgRegRun
//
this.pgRegRun.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.btnRefresh,
this.dgRegRun,
this.txtDebug,
this.btnDeleteSelected,
this.label1});
this.pgRegRun.Location = new System.Drawing.Point(4, 21);
this.pgRegRun.Name = "pgRegRun";
this.pgRegRun.Size = new System.Drawing.Size(432, 359);
this.pgRegRun.TabIndex = 0;
this.pgRegRun.Text = "注册表启动项";
this.pgRegRun.Click += new System.EventHandler(this.pgRegRun_Click);
//
// dgRegRun
//
this.dgRegRun.DataMember = "";
this.dgRegRun.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dgRegRun.Location = new System.Drawing.Point(8, 24);
this.dgRegRun.Name = "dgRegRun";
this.dgRegRun.Size = new System.Drawing.Size(408, 296);
this.dgRegRun.TabIndex = 4;
//
// txtDebug
//
this.txtDebug.Enabled = false;
this.txtDebug.Location = new System.Drawing.Point(320, 328);
this.txtDebug.Name = "txtDebug";
this.txtDebug.TabIndex = 3;
this.txtDebug.Text = "textBox1";
//
// btnDeleteSelected
//
this.btnDeleteSelected.Location = new System.Drawing.Point(8, 328);
this.btnDeleteSelected.Name = "btnDeleteSelected";
this.btnDeleteSelected.TabIndex = 2;
this.btnDeleteSelected.Text = "删除选定项";
this.btnDeleteSelected.Click += new System.EventHandler(this.btnDeleteSelected_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(112, 16);
this.label1.TabIndex = 0;
this.label1.Text = "注册表中的启动项";
//
// stbGreensLeaf
//
this.stbGreensLeaf.Location = new System.Drawing.Point(0, 415);
this.stbGreensLeaf.Name = "stbGreensLeaf";
this.stbGreensLeaf.Size = new System.Drawing.Size(464, 22);
this.stbGreensLeaf.TabIndex = 1;
this.stbGreensLeaf.Text = "绿叶的工具";
//
// btnRefresh
//
this.btnRefresh.Location = new System.Drawing.Point(96, 328);
this.btnRefresh.Name = "btnRefresh";
this.btnRefresh.TabIndex = 5;
this.btnRefresh.Text = "刷新";
this.btnRefresh.Click += new System.EventHandler(this.button1_Click);
//
// button1
//
this.button1.Enabled = false;
this.button1.Location = new System.Drawing.Point(184, 328);
this.button1.Name = "button1";
this.button1.TabIndex = 6;
this.button1.Text = "导出注册表";
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// frmGreensLeafTool
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(464, 437);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.stbGreensLeaf,
this.tabControl1});
this.Name = "frmGreensLeafTool";
this.Text = "绿叶的工具";
this.tabControl1.ResumeLayout(false);
this.pgRegRun.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgRegRun)).EndInit();
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmGreensLeafTool());
} private void ReloadDataTable()
{
dtRegRun.Clear();
dtRegRun.Columns.Clear();
int intKeyCount = 0;
dtRegRun.Columns.Add("序号");
dtRegRun.Columns.Add("位置");
dtRegRun.Columns.Add("键名");
dtRegRun.Columns.Add("键值");
this.txtDebug.Text = "";
{//从LocalMachine\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run下获取键名、键值
rkRegRun=Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
string[] strarrRegRun = rkRegRun.GetValueNames();
foreach(string strRegRun in strarrRegRun)
{
intKeyCount ++;
drow=dtRegRun.NewRow(); drow[0]=intKeyCount.ToString("00");
drow[1]="LocalMachine";
drow[2]=strRegRun;
drow[3]=rkRegRun.GetValue(strRegRun) ;
dtRegRun.Rows.Add(drow);
}
} {//从CurrentUser\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run下获取键名、键值
rkRegRun=Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
string[] strarrRegRun = rkRegRun.GetValueNames();
foreach(string strRegRun in strarrRegRun)
{
intKeyCount ++;
drow=dtRegRun.NewRow(); drow[0]=intKeyCount.ToString("00");
drow[1]="CurrentUser";
drow[2]=strRegRun;
drow[3]=rkRegRun.GetValue(strRegRun) ;
dtRegRun.Rows.Add(drow);
}
}
}
C:\Documents and Settings\All Users\「开始」菜单\程序\启动
不过可能还要查找一下系统变量”启动“在那个路径下如果是注册表启动项,那就在这个路径下User\\Software\\Microsoft\\Windows\\CurrentVersion\\run