| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 9452 人关注过本帖, 16 人收藏
标题:C#操作注册表全攻略
只看楼主 加入收藏
梦心
Rank: 4
来 自:福建平和
等 级:贵宾
威 望:13
帖 子:1910
专家分:0
注 册:2007-5-11
收藏
得分:0 
以下是引用skyzoneskyzone在2008-11-30 19:19的发言:

RegistryKey software = key.OpenSubKey("software\\test",true);  
这个地方到底对否?





对~~~我在XP+VS2008下测试过...

我清高和我骄傲的倔强,在风中大声的唱:我不听,我不听~~做我自己最特别,呼呼~~啦啦~~~
我的博客园地址: [url]http://[/url]
2008-12-01 11:46
qq26275108
Rank: 2
等 级:论坛游民
帖 子:56
专家分:30
注 册:2009-3-22
收藏
得分:0 
非常有用,谢谢分享!
2009-08-02 11:14
zjchenzt
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-6-2
收藏
得分:0 
回复 10楼 jerry2060
但是远程电脑的注册表的操纵似乎不能使用这个方法进行啊。这个适用于本地
2010-06-02 11:07
smooth
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2015-6-9
收藏
得分:0 
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using
using System.Threading;
using Microsoft.Win32;//注册表命名空间

namespace MonitorFileRegedit
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.ShowInTaskbar = false;//隐藏任务栏通知区域图标
            this.Visible = false;//隐藏窗体
            while (true)
            {
                Thread.Sleep(1000);
                if (File.Exists(@"C:\ABC.txt"))
                {
                    File.Delete(@"C:\ABC.txt");
                }
            }
        }
    }
}
求:在上述代码中插入以下内容:先读取HKEY_CURRENT_USER\Software\TKeysoft\FileGee\FileSafeSingle", "ImportantCount"的数据,如果读出的数据不是10066328,则将"ImportantCount"的数据修改为10066328,数据类型为REG_DWORD,谢谢!
 
我在倒数第5个大括号后插入以下代码:
RegistryKey key = Registry.CURRENTUSER;
RegistryKey software = key.OpenSubKey("Software\\TKeysoft\\FileGee\\FileSafeSingle", true);
software.SetValue("ImportantCount", "10066328", RegistryValueKind.DWord);
Key.Close();

提示错误:
1、“Microsoft.Win32.Registry”并不包含“CURRENTUSER”的定义;
2、当前上下文中不存在名称“Key”.

[ 本帖最后由 smooth 于 2015-6-9 20:12 编辑 ]
2015-06-09 20:10
smooth
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2015-6-9
收藏
得分:0 
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using
using System.Threading;
using Microsoft.Win32;//注册表命名空间

namespace MonitorFileRegedit
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.ShowInTaskbar = false;//隐藏任务栏通知区域图标
            this.Visible = false;//隐藏窗体
            while (true)
            {
                Thread.Sleep(1000);
                if (File.Exists(@"C:\ABC.txt"))
                {
                    File.Delete(@"C:\ABC.txt");
                }
            }
        }
    }
}
求:在上述代码中插入以下内容:先读取HKEY_CURRENT_USER\Software\TKeysoft\FileGee\FileSafeSingle", "ImportantCount"的数据,如果读出的数据不是10066328,则将"ImportantCount"的数据修改为10066328,数据类型为REG_DWORD,谢谢!
 
我在倒数第5个大括号后插入以下代码:
RegistryKey key = Registry.CURRENTUSER;
RegistryKey software = key.OpenSubKey("Software\\TKeysoft\\FileGee\\FileSafeSingle", true);
software.SetValue("ImportantCount", "10066328", RegistryValueKind.DWord);
Key.Close();

提示错误:
1、“Microsoft.Win32.Registry”并不包含“CURRENTUSER”的定义;
2、当前上下文中不存在名称“Key”.

[ 本帖最后由 smooth 于 2015-6-9 20:12 编辑 ]
2015-06-09 20:10
smooth
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2015-6-9
收藏
得分:0 
以下是引用smooth在2015-6-9 20:10:38的发言:

using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using
using System.Threading;
using Microsoft.Win32;//注册表命名空间

namespace MonitorFileRegedit
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.ShowInTaskbar = false;//隐藏任务栏通知区域图标
            this.Visible = false;//隐藏窗体
            while (true)
            {
                Thread.Sleep(1000);
                if (File.Exists(@"C:\ABC.txt"))
                {
                    File.Delete(@"C:\ABC.txt");
                }
            }
        }
    }
}
求:在上述代码中插入以下内容:先读取HKEY_CURRENT_USER\Software\TKeysoft\FileGee\FileSafeSingle", "ImportantCount"的数据,如果读出的数据不是10066328,则将"ImportantCount"的数据修改为10066328,数据类型为REG_DWORD,谢谢!
 
我在倒数第5个大括号后插入以下代码:
RegistryKey key = Registry.CURRENTUSER;
RegistryKey software = key.OpenSubKey("Software\\TKeysoft\\FileGee\\FileSafeSingle", true);
software.SetValue("ImportantCount", "10066328", RegistryValueKind.DWord);
Key.Close();

提示错误:
1、“Microsoft.Win32.Registry”并不包含“CURRENTUSER”的定义;
2、当前上下文中不存在名称“Key”.

搞定了,原来C#对大小写敏感,把CURRENTUSER修改为CurrentUser,Key修改为key就可以了。
RegistryKey key = Registry.CurrentUser;
RegistryKey software = key.OpenSubKey("Software\\TKeysoft\\FileGee\\FileSafeSingle", true);
software.SetValue("ImportantCount", "10066328", RegistryValueKind.DWord);
key.Close();
2015-06-09 22:02
快速回复:C#操作注册表全攻略
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018378 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved