注册表问题

主  题:  注册表问题?
作  者:  MikeWKL (星星之盾)
等  级:  ^^
信 誉 值:  100
所属论坛:  .NET技术 C#
问题点数:  10
回复次数:  6
发表时间:  2003-9-28 14:34:50

如何写注册表,将 AAA.exe(一个可执行文件) 放入Windows 的“开始”菜单中“程序”下的“启动”组里?

谢谢!



回复人: Reeezak(收破烂的) ( 二级(初级)) 信誉:100 2003-9-28 16:22:25 得分:2

你在做安装项目的时候可以写入
如果是用VS。net的话,可以在安装项目建立完了之后,在那个窗口里面右键,然后慢慢选择就是了^_^

回复人: gleaf() ( 二级(初级)) 信誉:100 2003-9-28 17:03:16 得分:4

使用Registry 来获取。

RegistryKey rkRegRun;
rkRegRun=Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\run",true);

后面的那个true,表示你可以删掉run里面的Value

不写那个true就已经可以读了。

回复人: gleaf() ( 二级(初级)) 信誉:100 2003-9-28 17:05:36 得分:0

下面是我以前写的一段代码。

你可以使用代码的片断,但是不能直接原样使用这些代码。如果希望原样使用这些代码的话,必须得到我本人的书面允许。

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
            //

回复人: gleaf() ( 二级(初级)) 信誉:100 2003-9-28 17:06:04 得分:0

        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);
        }
    }
}

回复人: xeonwei(以下信息不对外公开) ( 一级(初级)) 信誉:100 2003-9-28 17:23:00 得分:4

如果单纯放在启动菜单下,要找注册表吗?这个路径不行吗?
C:\Documents and Settings\All Users\「开始」菜单\程序\启动
不过可能还要查找一下系统变量”启动“在那个路径下

如果是注册表启动项,那就在这个路径下User\Software\Microsoft\Windows\CurrentVersion\run

回复人: MikeWKL(星星之盾) ( 二级(初级)) 信誉:100 2003-9-28 17:32:17 得分:0

感谢各位!

我要就是:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
结!

该问题已经结贴 ,得分记录: Reeezak (2)、 gleaf (4)、 xeonwei (4)、

Contributors: FHL