2009年2月16日 星期一

C# 設定和取得機碼(Registry Key)的值

設定機碼(Registry Key)

string keyPathString = "SOFTWARE\\AB Tool";
Microsoft.Win32.RegistryKey start = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey programName = start.CreateSubKey(keyPathString);
programName.SetValue("Application Path", System.Windows.Forms.Application.StartupPath);
programName.Close();

執行的結果

------------------------------------------------------------------------------------------------------------------------------------

取得機碼(Registry Key) 的值

string pathString = null;
string keyPathString = "SOFTWARE\\AB Tool";
Microsoft.Win32.RegistryKey start = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey programName = start.OpenSubKey(keyPathString);
if (programName != null)
{
pathString = (string)programName.GetValue("Application Path");
}

------------------------------------------------------------------------------------------------------------------------------------

沒有留言:

張貼留言