Avatar of Tom Powers
Tom Powers

asked on 

I Can write to Registry Local Machine using VB SCript but in VB.NET write to same key I get System.UnauthorizedAccessException

I Can write to Registry Local Machine using VB SCript but in VB.NET write to same key I get System.UnauthorizedAccessException. Is there some way to code this VB.NET Gui I'm writing to write static values to HK\Local Machine instead of vbscript or Merge Reg Files.
here is gui
VB AUTO LOG APP
vb.net code
Imports Microsoft.Win32
Public Class Form1
    Public Sub RegValues()
        Dim oReg As RegistryKey
        oReg = Registry.LocalMachine.OpenSubKey("Software", True)
        oReg = oReg.OpenSubKey("Microsoft\Windows NT\CurrentVersion\Winlogon")

        oReg.SetValue("AutoAdminLogon", 1)
        oReg.Close()
    End Sub

Open in new window


vbscript
Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
 
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
strValueName = "AutoAdminLogon"
strValue = 1

objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue

Open in new window


I could write to Registry Local Machine in XP With VB6 ? aNY CLEVER CODE?
Visual Basic.NETVB ScriptWindows 7

Avatar of undefined
Last Comment
Tom Powers

8/22/2022 - Mon