■レジストリにキーを作成し値をセットする
(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# に関するメモ
(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# に関するメモ
※コメント投稿者のブログIDはブログ作成者のみに通知されます