troubleshooting Question

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

Avatar of Tom Powers
Tom Powers asked on
Visual Basic.NETVB ScriptWindows 7
8 Comments1 Solution416 ViewsLast Modified:
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

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

I could write to Registry Local Machine in XP With VB6 ? aNY CLEVER CODE?
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros