码迷,mamicode.com
首页 > Windows程序 > 详细

C# 32位程序在64位系统下注册表操作

时间:2016-10-25 23:48:45      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:try   64bit   sof   environ   ace   soft   null   注册   png   

 

  在64位的Windows操作系统中,为了兼容32位程序的运行,64位的Windows操作系统采用重定向机制。目的是为了能让32位程序在64位的操作系统不仅能操作关键文件文夹和关键的注册表并且又要避免与64位程序冲突

相关资料请查看32位程序在64位系统下运行的重定向机制

 

下面是以获取操作系统安装密匙KEY的案例:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;

namespace ReadProductKey
{
    class Program
    {
        static void Main(string[] args)
        {
            string BackupProductKeyDefault;
            RegistryKey localKey = null;
            try
            {
          //判断操作系统版本(64位\32位)打开注册表项 localKey
= RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem?RegistryView.Registry64: RegistryView.Registry32);
          //得到注册表键值 BackupProductKeyDefault
= localKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform").GetValue("BackupProductKeyDefault", "").ToString(); Console.WriteLine(BackupProductKeyDefault); Console.ReadLine(); } catch (Exception ex) { } } } }

程序执行界面:

技术分享

注意:如果以 RegistryView.Registry32打开注册表项,并编译为32位版本的程序是不能获取系统关键注册表键值的

原文地址:http://www.cnblogs.com/iamlucky/p/5998510.html

C# 32位程序在64位系统下注册表操作

标签:try   64bit   sof   environ   ace   soft   null   注册   png   

原文地址:http://www.cnblogs.com/iamlucky/p/5998510.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!