気ままに

おゆみ野周辺のウォーキングを中心に、老後の自分のための今の記録。
気が向いたら書きます。

C# レジストリに値をセット

2005-03-08 06:23:08 | Program
■レジストリにキーを作成し値をセットする
(1).Microsoft.Win32 名前空間を使う
(2).RegistryKey クラスを使う

【参考】
http://www.atmarkit.co.jp/fdotnet/dotnettips/124regset/regset.html



#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

#endregion

namespace Test011
{
  class Program
  {
    static void Main(string[] args)
    {
      // キー名
      string sRegKey = @"SOFTWAREhi_tagTest";
      // 値の名前
      string sRegName = "TestVal";
      // 値
      string sRegVal = "TestData";

      try {
        // キーを HKY_LOCALMACHINE に新規作成
        RegistryKey rRegKey
           = Registry.LocalMachine.CreateSubKey(sRegKey);

        // 値をセット
        rRegKey.SetValue(sRegName, sRegVal);

        rRegKey.Close();
      }
      catch (Exception ex) {
        // エラー表示
        Console.WriteLine(ex.Message);
      }
    }
  }
}



プログラム学習室C# に関するメモ


最新の画像もっと見る

コメントを投稿