2011-06-12 173 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文件的内容。