C# 32位程序在64位系統下注冊表操作


 

  在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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM