注册表二进制值操作

.NET下,对注册表的操作容易多了,其中RegistryKey.SetValue()具有智能性,即可以根据值判断出值类型为哪种。

// NoDrives.cs
// .NET下操作注册表——隐藏驱动器C
using System;

using Microsoft.Win32;

 

class Reg

{

    public static void Main()

    {

        String name = @"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer";

        bool writeable = true;

 

        // 隐藏驱动器C的所需的值

        // 该项键值值类型为REG_BINARY

        // 对应于.NET中的System.Byte[]类型

        Byte[] rkvalue = { 0x04, 0x00, 0x00, 0x00 };

       

        RegistryKey rk = Registry.CurrentUser.OpenSubKey( name, writeable );

        rk.SetValue( "NoDrives", rkvalue );

        rk.Close();

    }

}

posted @ 2006-02-05 14:01  glimix  阅读(1749)  评论(2编辑  收藏  举报