Jump to content

Does RegWrite() require #RequireAdmin?


Recommended Posts

Been exchanging values between multiple scripts via ini file and thought to try out RegWrite()/RegRead() but for some reason it fails, Then tried run as Admin and that does the trick. So now found it annoying with uac popup using #RequireAdmin

thought to even tried RunAs(admin...RegWrite()) with admin user and pass but it also fails to write unless run as  #RequireAdmin.

did i missed something or admin is required with this simple task?

Link to comment
Share on other sites

2 hours ago, zeenmakr said:

did i missed something or admin is required with this simple task?

If you are trying to manipulate anything under HKLM, then your process needs to be elevated.  Elevation is not required to manipulate the HKCU hive.

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

So is this true? I can't get my script to write to HKCU, but it will read values just fine. I created the path (Computer\HKEY_CURRENT_USER\Software\Seadoggie01\TakeControl) in case RegWrite wouldn't do that, but it refuses to write anything. RegWrite returns False with no error

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

2 hours ago, seadoggie01 said:

So is this true?

I just tested it again on both Windows 7 & 10, logged in as an Administrator.  Running the script below, it ran without any errors when writing to the HKCU hive.  When I changed it to write to the HKLM hive, without #RequireAdmin, I get @error = 1 (unable to open requested key).

What is odd about your statement, if I understood it correctly, is that you got back a FALSE return without @error set to a non-zero value.  The help file explicitly states that if it is not successful, it will return False and set @error to a non-zero value.

For the record, the registry key did not exist before running the script.

#include <Constants.au3>

RegWrite("HKCU\Software\AAAAA", "A3Test", "REG_SZ", "This is a test value.")
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "RegWrite failed with @error =" & @error)

MsgBox($MB_ICONINFORMATION, "INFO", "RegWrite was successful.")

Or

#include <Constants.au3>

If Not RegWrite("HKCU\Software\AAAAA", "A3Test", "REG_SZ", "This is a test value.") Then
    Exit MsgBox($MB_ICONERROR, "ERROR", "RegWrite failed with @error =" & @error)
EndIf

MsgBox($MB_ICONINFORMATION, "INFO", "RegWrite was successful.")

They both give the same results.

Edited by TheXman
Correction - I get @error = 1 without #RequireAdmin when writing to HKLM
Link to comment
Share on other sites

FML. Apparently, $REG_SZ =/= "REG_SZ" and RegWrite doesn't accept the value from AutoItConstants.au3

I don't know why I thought I needed to use the variable, but I did. Please pardon my brain farts. Need more coffee.

Edit: But thank you for testing that for me! I really appreciate it :)

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

20 hours ago, TheXman said:

What is odd about your statement, if I understood it correctly, is that you got back a FALSE return without @error set to a non-zero value.  The help file explicitly states that if it is not successful, it will return False and set @error to a non-zero value.

@TheXman I can confirm that I have also experienced similar silent fails. Windows 10.  :)

 

Skysnake

Why is the snake in the sky?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...