Bug in Regwrite in HKEY_LOCAL_MACHINE

Get help with using AutoHotkey and its commands and hotkeys
wiens
Posts: 24
Joined: 08 Dec 2015, 05:22

Bug in Regwrite in HKEY_LOCAL_MACHINE

08 Mar 2019, 04:27

Hello,

When you write registry key it will not work in HKEY_LOCAL_MACHINE:

RegWrite, REG_SZ, HKEY_LOCAL_MACHINE\SOFTWARE\TestKey, MyValueName, Test Value

When you write registry it works fine in HKEY_CURRENT_USER:

RegWrite, REG_SZ, HKEY_CURRENT_USER\SOFTWARE\TestKey, MyValueName, Test Value

So the bug is in HKEY_LOCAL_MACHINE.
By the way you don't need any admin rights to write this key in HKEY_LOCAL_MACHINE if you do it manually.

This issue exist in AHK version 1.1.30.01.
just me
Posts: 7403
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

08 Mar 2019, 05:14

By the way you don't need any admin rights to write this key in HKEY_LOCAL_MACHINE if you do it manually.
Interesting, on my Win 10 system I need them.
ErrorLevel

[v1.1.04+]: This command is able to throw an exception on failure. For more information, see Runtime Errors.

ErrorLevel is set to 1 if there was a problem or 0 otherwise.

A_LastError is set to the result of the operating system's GetLastError() function.
What do they tell you?
wiens
Posts: 24
Joined: 08 Dec 2015, 05:22

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

08 Mar 2019, 08:26

The values are:
ErrorLevel = 1
A_LastError = 5
wiens
Posts: 24
Joined: 08 Dec 2015, 05:22

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

13 Mar 2019, 23:13

What is causing this error if it is not in admin rights?
CloakerSmoker
Posts: 29
Joined: 07 Sep 2018, 15:54

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

14 Mar 2019, 02:16

Edit: About a minute after hitting submit I stumbled across this (On a totally different MSDN page in my defense):
When you call the RegOpenKeyEx function, the system checks the requested access rights... If the user does not have the correct access to the registry key, the open operation fails.
So the problem is that your account doesn't have permission to create the key, which matches what you got for ErrorLevel and LastError.
However, I'm not sure why RegEdit would let you while RegWrite fails.

The rest of this post is incorrect, so you can just ignore it.
Spoiler
XShayanX
Posts: 62
Joined: 16 Sep 2018, 04:48

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

13 Sep 2019, 08:13

I'm on v1.1.30.01 currently, any news on when this is going to get fixed? I have the same issue, I can't write to HKLM.
This is my thread: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=67974&p=292326#p292326
just me
Posts: 7403
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

13 Sep 2019, 08:43

wiens wrote: The values are:
ErrorLevel = 1
A_LastError = 5
ERROR_ACCESS_DENIED

5 (0x5)

Access is denied.

Source
swagfag
Posts: 4070
Joined: 11 Jan 2017, 17:59

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

13 Sep 2019, 09:28

never heard of writing to HKLM not requiring admin access. ur regedit must have been running elevated
XShayanX
Posts: 62
Joined: 16 Sep 2018, 04:48

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

14 Sep 2019, 04:30

@just me Nice I just saw your post here, so it means we're on the same boat, I understand that I'm getting Access denied (Error 5) but I am running my script as Administrator, I don't know what I'm missing?
Last edited by XShayanX on 14 Sep 2019, 13:20, edited 1 time in total.
gwarble
Posts: 461
Joined: 30 Sep 2013, 15:01

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

14 Sep 2019, 11:49

try it from your same shk script with Run, %comspec% reg add hklm/...

Then you will make sure both methods are using the same elevation coming from the same process... My guess is they will act the same, I’ll try on my machine later
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
wiens
Posts: 24
Joined: 08 Dec 2015, 05:22

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

27 Sep 2019, 04:24

gwarble, it didn't work with that workaround for me.
gwarble
Posts: 461
Joined: 30 Sep 2013, 15:01

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

27 Sep 2019, 08:18

that means its an elevation/permission issue as was first recommended
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Bug in Regwrite in HKEY_LOCAL_MACHINE

28 Sep 2019, 20:27

I doubt there's a bug here.

What does MsgBox % A_IsAdmin say?

What permissions does your account have to this registry key? You can check by right clicking on the key in regedit and selecting Permissions....

With UAC set to "Notify me only when applications try to make changes to my computer (default)", it will not notify you when you launch certain system applications, such as regedit, even though they are elevated to admin. Some system applications will only run with limited permissions if the current user is not a member of the Administrators group, while others will not run at all in that situation, or will require you to enter an admin username and password.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Saarthak Kamra, Smoothglobal, TXShooter and 44 guests