2012-07-14 130 views
2

可能重複:
Looking for C# registry class
Way to write on registry location如何通過C#中的代碼編輯Windows註冊表值(註冊表)?

我試圖在C#程序,通過做幾件事情(清除臨時文件夾提升窗口的速度,預取文件夾等)

但爲了使程序強大,我需要編輯註冊表值.. 我怎麼能去做 ?

+3

「提升窗口的速度」 - 好吧......現在,做不使用註冊表值實際上損害的Windows性能?以什麼方式?或者,正如他們所說,它只是蛇油。我並不孤單,認爲它只是安慰劑(如果有的話),例如請參閱http://social.technet.microsoft.com/Forums/en/w7itproappcompat/thread/0407992a-b9b0-4f14-b9d6-7243ed21a110例如 - 「註冊表清理程序*所有*蛇油。 (...)肯布萊克,微軟MVP(Windows桌面體驗)自2003年以來' – 2012-07-14 15:48:12

回答

0
+0

謝謝,但你能否提供一個例子.. 我的意思是,我怎麼能達到並改變MenuShowDelay值例如? – vexe 2012-07-14 15:46:37

2

您可能需要閱讀本article

public string Read(string KeyName) 
{ 
    // Opening the registry key 
    RegistryKey rk = baseRegistryKey ; 
    // Open a subKey as read-only 
    RegistryKey sk1 = rk.OpenSubKey(subKey); 
    // If the RegistrySubKey doesn't exist -> (null) 
    if (sk1 == null) 
    { 
     return null; 
    } 
    else 
    { 
     try 
     { 
      // If the RegistryKey exists I get its value 
      // or null is returned. 
      return (string)sk1.GetValue(KeyName.ToUpper()); 
     } 
     catch (Exception e) 
     { 
      // AAAAAAAAAAARGH, an error! 
      ShowErrorMessage(e, "Reading registry " + KeyName.ToUpper()); 
      return null; 
     } 
    } 
} 
+0

代碼中的'else'完全沒有意義(對不起,我的寵物狗) – 2012-07-14 16:01:29

+0

你是什麼意思? – Adil 2012-07-14 16:12:03

+0

如果不離開方法就沒有辦法返回null,是嗎?所以'else'子句是多餘的。不用說,if(sk == null){return null; }'只有'sk'不是'null'纔會被執行。這當然是完全有效的代碼,只是多餘的。這只是一個風格問題。我個人不喜歡它帶來的額外嵌套。我明白,有些人更喜歡更明確的意圖,雖然。 – 2012-07-14 17:54:22