2012-01-05 70 views
0

我在寫一個C#模塊;我需要從註冊表路徑'HKEY_LOCAL_MACHINE/Software/Avtec,Inc/LicenseKey'中檢索一個名爲'LicenseKey'的密鑰的值,並將其存儲在一個名爲「pml.bin」的bin文件中。我有一些代碼問題。任何人都可以幫助我的代碼?提前致謝。從註冊表中讀取值並將其存儲在bin文件中

+0

你可以顯示你有問題的代碼嗎? – 2012-01-05 06:05:22

+0

沒有看到附加的截圖。你還可以發佈有關此事的代碼嗎? – dotnetnate 2012-01-05 06:05:32

+0

請點擊此處鏈接 http://stackoverflow.com/questions/8738554/reading-value-from-registry-and-storing-it-in-a-bin-file-in-a-folder – 2012-01-05 06:32:45

回答

1

我試着用下面的代碼,並沒有面臨任何問題。檢查註冊表路徑並確保路徑中正確的斜槓「\」。用你的代碼檢查下面的代碼,

 RegistryKey key = Registry.LocalMachine; 
     RegistryKey dataKey = key.OpenSubKey(@"Software\Avtec.Inc\LicenseKey"); 
     string licenceKey = dataKey.GetValue("required field name").ToString(); 

     using (BinaryWriter b = new BinaryWriter(File.Open("file.bin", FileMode.Create))) 
     { 
      b.Write(licenceKey); 
      b.Close(); 
     } 
相關問題