Sign in to follow this  
Followers 0
SlowCoder74

Trouble writing to registry in Windows 7

10 posts in this topic

Here's my code:

UpdateAutoLogon(1,"Mylogin","MyPassword","MyDomain")

Func UpdateAutoLogon($iEnabled,$sAutoLogonUserName,$sAutoLogonPassword,$sAutoLogonDomain)
local $ErrorNum = 0
local $sHive

$sHive = "HKLM"
if @OSArch = "X64" or @OSArch = "IA64" then $sHive = "HKLM64"
;
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","AutoAdminLogon","REG_SZ",$iEnabled)
if @error<>0 then $ErrorNum = @error
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","ForceAutoLogon","REG_SZ",$iEnabled)
if @error<>0 then $ErrorNum = @error
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultUserName","REG_SZ",$sAutoLogonUserName)
if @error<>0 then $ErrorNum = @error
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultPassword","REG_SZ",$sAutoLogonPassword)
if @error<>0 then $ErrorNum = @error
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultDomainName","REG_SZ",$sAutoLogonDomain)
if @error<>0 then $ErrorNum = @error
return $ErrorNum
EndFunc

It works great in XP. But when I try to use it in Windows 7, I get an error 1, which means it can't find the key.

I added the

if @OSArch = "X64" or @OSArch = "IA64" then $sHive = "HKLM64"

to see if that was the problem. I don't even know if it's relevent. In any case, it didn't fix the problem.

Any ideas?

Share this post


Link to post
Share on other sites



Which one is failing? Do you have write access to the registry?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Which one is failing? Do you have write access to the registry?

They all fail. Yes, I am administrator on the machine, and can manage registry data through regedit.

Share this post


Link to post
Share on other sites

I found this reference which mentions this issue, and some suggestions that might work for you. Specifically the mention of this key HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindows NTCurrentVersionWinlogonDefaultUserName on x64 systems.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yes,some keys are different or don't exist anymore in Win7/Vista. And for x64 bits machines, some registry keys are different too, and some system folders too,so be carefull

Share this post


Link to post
Share on other sites

I found this reference which mentions this issue, and some suggestions that might work for you. Specifically the mention of this key HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindows NTCurrentVersionWinlogonDefaultUserName on x64 systems.

Coming back to this after a while ...

I read through that, and pulled up nothing valuable. Maybe I don't know how to read. ;)

I've compiled my code as 32 bit and 64 bit, tried HKLM and HKLM64, and WOW6432Node, and continue to get a failure.

Note, that I can read the data fine using

$sHive = "HKLM"
if @OSArch = "X64" or @OSArch = "IA64" then $sHive = "HKLM64" ;if 64bit system, modify hive location
$RegAutoLogon = regread($sHive & "SOFTWAREMicrosoftWindows NTCurrentVersionWinlogon","AutoAdminLogon")

Share this post


Link to post
Share on other sites

This works fine for me on Win 7 when I add #RequireAdmin at the top of the script.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

This works fine for me on Win 7 when I add #RequireAdmin at the top of the script.

Son ... Of ... A ... Bleep ...

Yes, I see it works for me also. This means it's an access problem, even though I am a network admin, as well as explicitly in the local Administrators group on the PC. No way to get past that without it prompting me if it's ok?

Share this post


Link to post
Share on other sites

Unfortunately, short of turning UAC off, you're stuck with it in Win 7.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Unfortunately, short of turning UAC off, you're stuck with it in Win 7.

Ugh ... grrr ... pffff ... Well, that stinks. But it's better than nothing. Thank you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0