Vb.net – Edit Registry in Vb.net

registryvb.net

I need to edit registry in vb.net (2010) i know how to edit it in a .reg file but not in visual basic 2010 if it helps this is the code

    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

Best Answer

The Microsoft.Win32.RegistryKey class will provide you with all the functionality you need to read, modify and delete registry keys and values.

For example:

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);

The subkey HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies \system will actually exist, I only show a test that you'd do if you were creating your own keys and values for completeness.

Related Topic