Aquí les dejo un (casi)completo set de utilidades para manejar el registro de windows desde una aplicación .Net, tiene todo tipo de funcionalidades.
Ejemplos de uso:
Código fuente:
http://pastebin.com/cNM1j8Uh
Saludos!
Ejemplos de uso:
Código (vbnet) [Seleccionar]
----------------
Set RegInfo Instance
----------------
Dim regInfo As New RegEdit.RegInfo
With regInfo
.RootKeyName = "HKCU"
.SubKeyPath = "Subkey Path"
.ValueName = "Value Name"
.ValueType = Microsoft.Win32.RegistryValueKind.String
.ValueData = "Hello World!"
End With
Dim regInfoByte As New RegEdit.RegInfo(Of Byte())
With regInfoByte
.RootKeyName = "HKCU"
.SubKeyPath = "Subkey Path"
.ValueName = "Value Name"
.ValueType = Microsoft.Win32.RegistryValueKind.Binary
.ValueData = System.Text.Encoding.ASCII.GetBytes("Hello World!")
End With
----------------
Create SubKey
----------------
RegEdit.CreateSubKey(fullKeyPath:="HKCU\Subkey Path\")
RegEdit.CreateSubKey(rootKeyName:="HKCU",
subKeyPath:="Subkey Path")
RegEdit.CreateSubKey(regInfo:=regInfoByte)
Dim regKey1 As Microsoft.Win32.RegistryKey =
RegEdit.CreateSubKey(fullKeyPath:="HKCU\Subkey Path\",
registryKeyPermissionCheck:=Microsoft.Win32.RegistryKeyPermissionCheck.Default,
registryOptions:=Microsoft.Win32.RegistryOptions.None)
Dim regKey2 As Microsoft.Win32.RegistryKey =
RegEdit.CreateSubKey(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
registryKeyPermissionCheck:=Microsoft.Win32.RegistryKeyPermissionCheck.Default,
registryOptions:=Microsoft.Win32.RegistryOptions.None)
Dim regInfo2 As RegEdit.RegInfo(Of String) = RegEdit.CreateSubKey(Of String)(fullKeyPath:="HKCU\Subkey Path\")
Dim regInfo3 As RegEdit.RegInfo(Of String) = RegEdit.CreateSubKey(Of String)(rootKeyName:="HKCU",
subKeyPath:="Subkey Path")
----------------
Create Value
----------------
RegEdit.CreateValue(fullKeyPath:="HKCU\Subkey Path\",
valueName:="Value Name",
valueData:="Value Data",
valueType:=Microsoft.Win32.RegistryValueKind.String)
RegEdit.CreateValue(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
valueName:="Value Name",
valueData:="Value Data",
valueType:=Microsoft.Win32.RegistryValueKind.String)
RegEdit.CreateValue(regInfo:=regInfoByte)
RegEdit.CreateValue(Of String)(fullKeyPath:="HKCU\Subkey Path\",
valueName:="Value Name",
valueData:="Value Data",
valueType:=Microsoft.Win32.RegistryValueKind.String)
RegEdit.CreateValue(Of String)(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
valueName:="Value Name",
valueData:="Value Data",
valueType:=Microsoft.Win32.RegistryValueKind.String)
RegEdit.CreateValue(Of Byte())(regInfo:=regInfoByte)
----------------
Copy KeyTree
----------------
RegEdit.CopyKeyTree(sourceFullKeyPath:="HKCU\Source Subkey Path\",
targetFullKeyPath:="HKCU\Target Subkey Path\")
RegEdit.CopyKeyTree(sourceRootKeyName:="HKCU",
sourceSubKeyPath:="Source Subkey Path\",
targetRootKeyName:="HKCU",
targetSubKeyPath:="Target Subkey Path\")
----------------
Move KeyTree
----------------
RegEdit.MoveKeyTree(sourceFullKeyPath:="HKCU\Source Subkey Path\",
targetFullKeyPath:="HKCU\Target Subkey Path\")
RegEdit.MoveKeyTree(sourceRootKeyName:="HKCU",
sourceSubKeyPath:="Source Subkey Path\",
targetRootKeyName:="HKCU",
targetSubKeyPath:="Target Subkey Path\")
----------------
Copy SubKeys
----------------
RegEdit.CopySubKeys(sourceFullKeyPath:="HKCU\Source Subkey Path\",
targetFullKeyPath:="HKCU\Target Subkey Path\")
RegEdit.CopySubKeys(sourceRootKeyName:="HKCU",
sourceSubKeyPath:="Source Subkey Path\",
targetRootKeyName:="HKCU",
targetSubKeyPath:="Target Subkey Path\")
----------------
Move SubKeys
----------------
RegEdit.MoveSubKeys(sourceFullKeyPath:="HKCU\Source Subkey Path\",
targetFullKeyPath:="HKCU\Target Subkey Path\")
RegEdit.MoveSubKeys(sourceRootKeyName:="HKCU",
sourceSubKeyPath:="Source Subkey Path\",
targetRootKeyName:="HKCU",
targetSubKeyPath:="Target Subkey Path\")
----------------
Copy Value
----------------
RegEdit.CopyValue(sourceFullKeyPath:="HKCU\Source Subkey Path\",
sourceValueName:="Value Name",
targetFullKeyPath:="HKCU\Target Subkey Path\",
targetValueName:="Value Name")
RegEdit.CopyValue(sourceRootKeyName:="HKCU",
sourceSubKeyPath:="Source Subkey Path\",
sourceValueName:="Value Name",
targetRootKeyName:="HKCU",
targetSubKeyPath:="Target Subkey Path\",
targetValueName:="Value Name")
----------------
Move Value
----------------
RegEdit.MoveValue(sourceFullKeyPath:="HKCU\Source Subkey Path\",
sourceValueName:="Value Name",
targetFullKeyPath:="HKCU\Target Subkey Path\",
targetValueName:="Value Name")
RegEdit.MoveValue(sourceRootKeyName:="HKCU",
sourceSubKeyPath:="Source Subkey Path\",
sourceValueName:="Value Name",
targetRootKeyName:="HKCU",
targetSubKeyPath:="Target Subkey Path\",
targetValueName:="Value Name")
----------------
DeleteValue
----------------
RegEdit.DeleteValue(fullKeyPath:="HKCU\Subkey Path\",
valueName:="Value Name",
throwOnMissingValue:=True)
RegEdit.DeleteValue(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
valueName:="Value Name",
throwOnMissingValue:=True)
RegEdit.DeleteValue(regInfo:=regInfoByte,
throwOnMissingValue:=True)
----------------
Delete SubKey
----------------
RegEdit.DeleteSubKey(fullKeyPath:="HKCU\Subkey Path\",
throwOnMissingSubKey:=False)
RegEdit.DeleteSubKey(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
throwOnMissingSubKey:=False)
RegEdit.DeleteSubKey(regInfo:=regInfoByte,
throwOnMissingSubKey:=False)
----------------
Exist SubKey?
----------------
Dim exist1 As Boolean = RegEdit.ExistSubKey(fullKeyPath:="HKCU\Subkey Path\")
Dim exist2 As Boolean = RegEdit.ExistSubKey(rootKeyName:="HKCU",
subKeyPath:="Subkey Path")
----------------
Exist Value?
----------------
Dim exist3 As Boolean = RegEdit.ExistValue(fullKeyPath:="HKCU\Subkey Path\",
valueName:="Value Name")
Dim exist4 As Boolean = RegEdit.ExistValue(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
valueName:="Value Name")
----------------
Value Is Empty?
----------------
Dim isEmpty1 As Boolean = RegEdit.ValueIsEmpty(fullKeyPath:="HKCU\Subkey Path\",
valueName:="Value Name")
Dim isEmpty2 As Boolean = RegEdit.ValueIsEmpty(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
valueName:="Value Name")
----------------
Export Key
----------------
RegEdit.ExportKey(fullKeyPath:="HKCU\Subkey Path\",
outputFile:="C:\Backup.reg")
RegEdit.ExportKey(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
outputFile:="C:\Backup.reg")
----------------
Import RegFile
----------------
RegEdit.ImportRegFile(regFilePath:="C:\Backup.reg")
----------------
Jump To Key
----------------
RegEdit.JumpToKey(fullKeyPath:="HKCU\Subkey Path\")
RegEdit.JumpToKey(rootKeyName:="HKCU",
subKeyPath:="Subkey Path")
----------------
Find SubKey
----------------
Dim regInfoSubkeyCol As IEnumerable(Of RegEdit.Reginfo) =
RegEdit.FindSubKey(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
subKeyName:="Subkey Name",
matchFullSubKeyName:=False,
ignoreCase:=True,
searchOption:=IO.SearchOption.AllDirectories)
For Each reg As RegEdit.RegInfo In regInfoSubkeyCol
Debug.WriteLine(reg.RootKeyName)
Debug.WriteLine(reg.SubKeyPath)
Debug.WriteLine(reg.ValueName)
Debug.WriteLine(reg.ValueData.ToString)
Debug.WriteLine("")
Next reg
----------------
Find Value
----------------
Dim regInfoValueNameCol As IEnumerable(Of RegEdit.Reginfo) =
RegEdit.FindValue(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
valueName:="Value Name",
matchFullValueName:=False,
ignoreCase:=True,
searchOption:=IO.SearchOption.AllDirectories)
For Each reg As RegEdit.RegInfo In regInfoValueNameCol
Debug.WriteLine(reg.RootKeyName)
Debug.WriteLine(reg.SubKeyPath)
Debug.WriteLine(reg.ValueName)
Debug.WriteLine(reg.ValueData.ToString)
Debug.WriteLine("")
Next reg
----------------
Find Value Data
----------------
Dim regInfoValueDataCol As IEnumerable(Of RegEdit.Reginfo) =
RegEdit.FindValueData(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
valueData:="Value Data",
matchFullData:=False,
ignoreCase:=True,
searchOption:=IO.SearchOption.AllDirectories)
For Each reg As RegEdit.RegInfo In regInfoValueDataCol
Debug.WriteLine(reg.RootKeyName)
Debug.WriteLine(reg.SubKeyPath)
Debug.WriteLine(reg.ValueName)
Debug.WriteLine(reg.ValueData.ToString)
Debug.WriteLine("")
Next reg
----------------
Get...
----------------
Dim rootKeyName As String = RegEdit.GetRootKeyName(registryPath:="HKCU\Subkey Path\")
Dim subKeyPath As String = RegEdit.GetSubKeyPath(registryPath:="HKCU\Subkey Path\")
Dim rootKey As Microsoft.Win32.RegistryKey = RegEdit.GetRootKey(registryPath:="HKCU\Subkey Path\")
----------------
Get Value Data
----------------
Dim dataObject As Object = RegEdit.GetValueData(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
valueName:="Value Name")
Dim dataString As String = RegEdit.GetValueData(Of String)(fullKeyPath:="HKCU\Subkey Path\",
valueName:="Value Name",
registryValueOptions:=Microsoft.Win32.RegistryValueOptions.DoNotExpandEnvironmentNames)
Dim dataByte As Byte() = RegEdit.GetValueData(Of Byte())(regInfo:=regInfoByte,
registryValueOptions:=Microsoft.Win32.RegistryValueOptions.None)
Debug.WriteLine("dataByte=" & String.Join(",", dataByte))
-----------------
Set UserAccessKey
-----------------
RegEdit.SetUserAccessKey(fullKeyPath:="HKCU\Subkey Path",
userAccess:={RegEdit.ReginiUserAccess.AdministratorsFullAccess})
RegEdit.SetUserAccessKey(rootKeyName:="HKCU",
subKeyPath:="Subkey Path",
userAccess:={RegEdit.ReginiUserAccess.AdministratorsFullAccess,
RegEdit.ReginiUserAccess.CreatorFullAccess,
RegEdit.ReginiUserAccess.SystemFullAccess})
Código fuente:
http://pastebin.com/cNM1j8Uh
Saludos!