2011-06-12 153 views
2

我需要在vb.net(2010年)我知道如何是否有幫助這是代碼編輯註冊表中Vb.net

 Windows Registry Editor Version 5.00 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system] 
"dontdisplaylastusername"=dword:00000000 
"legalnoticecaption"="            Justin Tech" 
"legalnoticetext"="This computer system, including all related equipment, is the property of the Justint Tech and is solely for uses authorized by jUSITN tECH. You have no right to privacy on the system, and all information and activity 

on the system may be monitored. Any unauthorized use of the system may result in disciplinary action, civil or criminal penalties." 
"shutdownwithoutlogon"=dword:00000001 
"undockwithoutlogon"=dword:00000001
編輯在一個.reg文件,但不能在Visual Basic 2010編輯註冊表

回答

4

Microsoft.Win32.RegistryKey類將爲您提供讀取,修改和刪除註冊表項和值所需的所有功能。

例如:

using Microsoft.Win32; 

... 

RegistryKey myKey = Registry.LocalMachine.OpenSubKey(
     @"SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system", true); 

if(myKey == null) 
{ 
    myKey = Registry.LocalMachine.CreateSubKey(
      @"SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system", 
      RegistryKeyPermissionCheck.ReadWriteSubTree); 
} 

myKey.SetValue("dontdisplaylastusername", 0, RegistryValueKind.DWord); 
myKey.SetValue("legalnoticecaption", "Justin Tech", RegistryValueKind.String); 
myKey.SetValue("legalnoticetext", "This computer system...", 
               RegistryValueKind.String); 
myKey.SetValue("shutdownwithoutlogon", 1, RegistryValueKind.DWord); 
myKey.SetValue("undockwithoutlogon", 1, RegistryValueKind.DWord); 

的子項HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies \system實際上會存在,我只顯示一個測試,如果你創建自己的密鑰和值完整性,你會怎麼做。

2

只是作爲替代直接在VB.NET與註冊表項工作,你可以直接使用下面的代碼執行一個.reg文件:

Process.Start("regedit.exe", "fileName.reg /s") 

的/ s是默默地運行它。唯一的問題在於你可能會遇到其他人改變.reg文件的可能性,從而危及你的安全。但是,如果將.reg文件放在中心位置並使其成爲只讀位置,則可以對計算機執行此操作。這將允許您在不更改代碼的情況下更改.reg文件的內容。