Sign in to follow this  
Followers 0
JakeHelpdesk

RegWrite RequireAdmin Still no Luck for HKLM

8 posts in this topic

I have the following code as an example of my problem.

#RequireAdmin
RegWrite("HKEY_LOCAL_MACHINE\Test", "Test", "REG_SZ", "TestValue")
RegWrite("HKEY_CURRENT_USER\Test", "Test", "REG_SZ", "TestValue")

I can execute this and the "HKEY_CURRENT_USERTest" will be created, but the "HKEY_LOCAL_MACHINETest" will not.

I have also tried editing the registry with a batch file (That Works)

But If I call the batch file from within AutoIt, via Run() or RunWait() it doesn't work.

Any Ideas as to why I would be prevented from writing to the HKEY_LOCAL_MACHINE?

Share this post


Link to post
Share on other sites



For the Local Machine it's returning 1 (unable to open requested key)

For the Current User it's returning 0 (success)

I don't understand why it's unable to open requested key. I am able to do it manually, I am a local administrator on the PC.

Share this post


Link to post
Share on other sites

.....

I have also tried editing the registry with a batch file (That Works)

.....

 

could you post the batch file?


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I was trying to do this as a test, but here is what I'm actually working on.

This is the Batch File I'm trying to convert to an AutoIt Script.

REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "LegalNoticeCaption" /t REG_SZ /d "Legal Notice" /f

REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "LegalNoticeText" /t REG_SZ /d "This system is restricted to authorized users for legitimate business purposes and is subject to audit.  The actual or attempted unauthorized access, use, modification or copying of computer systems is a violation of Local laws." /f

REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "PasswordExpiryWarning" /t REG_DWORD /d 00000000 /f

exit

This is the AutoIt Code I have put together

#RequireAdmin
RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "LegalNoticeCaption", "REG_SZ", "Legal Notice")
MsgBox(0, "Error", @error)
RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "LegalNoticeText", "REG_SZ", "This system is restricted to authorized users for legitimate business purposes and is subject to audit.  The actual or attempted unauthorized access, use, modification or copying of computer systems is a violation of Local laws.")
MsgBox(0, "Error", @error)
RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "PasswordExpiryWarning", "REG_DWORD", 0)
MsgBox(0, "Error", @error)

The 3 MsgBoxes are throwing zeros meaning it works, but when I open regedit they aren't there.

Also, if I call the Batch File

Run('C:\Scripting\Temp\LegalNotice.bat')

That doesn't work either.

However if I just run the batch file from windows, it creates the keys fine.

Edited by JakeHelpdesk

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Be careful : if you are using a x64 operating system, maybe you have to use HKLM64 to write these values in the good key :

#RequireAdmin
RegWrite("HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "LegalNoticeCaption", "REG_SZ", "Legal Notice")
Edited by jguinch

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@OP - I realize you're trying to create in the Winlogon key, but please see below for why your original test (HKLMTest) was failing:

from the help file (which took it from MSDN):

An application cannot create a key that is a direct child of HKEY_USERS or HKEY_LOCAL_MACHINE. An application can create subkeys in lower levels of the HKEY_USERS or HKEY_LOCAL_MACHINE trees.



As has been pointed out, it is probably creating, but going into your Wow6432Node

Edited by JLogan3o13

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

Share this post


Link to post
Share on other sites

 

Be careful : if you are using a x64 operating system, maybe you have to use HKLM64 to write these values in the good key :

#RequireAdmin
RegWrite("HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "LegalNoticeCaption", "REG_SZ", "Legal Notice")

I could have sworn I tried that already..... but I just did what you said again, and it's working.

Thank you so much for your help

Sincerely,

Jake

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