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.UnauthorizedAccessE xception. 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.net code
vbscript
I could write to Registry Local Machine in XP With VB6 ? aNY CLEVER CODE?
here is gui
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
Pete the problem is that we have 8 different auto login accounts and each have different permissions and pertain to 8 different sections or Departments at the Hospital I work at so I just wanted to make a GUI that set AutoAdminlogin key Default username and password. I just don't understand why VBScript works but a .NET APP doesn't have Write access to LocalMachine/SOFTWARE\Micr osoft\Wind ows NT\CurrentVersion\Winlogon
No matter what method you use, it can only succeed after elevating Did you elevate before executing these scripts?
ASKER
Yes I used Runas Different User with admin rights on all desktops. I'm reading online about
Public Enumeration RegistryPermissionAccess but I have not clue what to code? Anybody got some magic code?
Public Enumeration RegistryPermissionAccess but I have not clue what to code? Anybody got some magic code?
"Runas Different User with admin rights" is not the same as elevating. When you logon (or runas) a different user with admin rights, you still need to elevate. So unless you didn't see a UAC prompt at some point, you haven yet elevated and write to HKLM will fail.
ASKER
I just run the vb script with admin rights my Username. So it's bizarre McKnife UAC is was set to never notify so I raised it to the top for notification but UAC never notifies me. So No Coders I guess?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks I know the workaround I'm going to use.
Computer Configuration, Policies, Windows Settings, Security Settings, Registry., Add Key and add the entry you require.