Edit registry in HKLM using Microsoft Access 2013 VBA?

I am trying to manipulate the registry from VBA code in Microsoft Access 2013 under Windows 7, 32-bit.  I don't have a problem in HKCU, but in HKLM I receive an error.

Dim ChangeReg
Set ChangeReg = CreateObject("WScript.Shell")
ChangeReg.RegWrite "HKLM\MyNewKey\", 1, "REG_DWORD"

...throws run-time error:  Invalid root in registry key "HKLM\MyNewKey\".

I am guessing this is security-related, and I would like to get around it without causing the user to need to click on a UAC dialog box or anything like that, if possible.  Suggestions?  Thanks.
AutomateMyOfficeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Luke ChungPresidentCommented:
You need admin rights to modify the machine entries. If the user doesn't have those rights, your app won't be able to make changes to that part of the registry.

Our paper on how to handle temporary data may help:
http://www.fmsinc.com/MicrosoftAccess/database-design/temporary-data.html
0
AutomateMyOfficeAuthor Commented:
I am getting the error even though I am an administrator on my development computer.  The end users will also have admin rights.

This is not a matter of storing data.  It is a need to have programmatic control over certain functions that depend on values in the registry, such as AutoRotation on a Windows 8 tablet.
0
Surone1Commented:
try this:

Dim ChangeReg
Set ChangeReg = CreateObject("WScript.Shell")
ChangeReg.RegWrite "HKLM\MyNewKey", 1, "REG_DWORD"
0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Luke ChungPresidentCommented:
Dealing with registry entries usually involves much more complicated Windows API calls to modify the registry. We have some of that code in our Total Visual SourceBook product (registry modules), but that may be overkill.

Are you supporting multiple users on the same device? If not, the built-in Access VBA commands GetSetting, SetSetting, DeleteSetting that I referenced earlier deals with the registry values without the complexity of using the Shell command.

Hope this helps.
0
AutomateMyOfficeAuthor Commented:
Surone1 -- Removing the trailing backslash changes the error to "Permisson denied," but i still can't create the key.

LukeChung -- I do not see where you earlier referenced GetSetting, etc.  (Spent a while googling SetSetting until I realized it is actually SaveSetting!)  These may help, and the SourceBook looks like a good resource as well.  

What I really need is:

a) to know whether it is possible for a user having admin rights to create, modify or delete registry values under HKLM (not HKCU) using Microsoft Access VBA, without the need to take any other special action, such as responding to a UAC dialog box,

b) a couple of lines of code, whether using SaveSetting, FMS modules, or anything else, showing how to accomplish the simple addition of a new key, as I was attempting to do with the snippet contained in my original question.

I appreciate any assistance that can be offered.
0
Surone1Commented:
the access denied would probably UAC related. as stated before you need administrator permission to write to HKLM.
it works fine for me, since i turned off UAC (probably also running as administrator)
0
Luke ChungPresidentCommented:
Sorry, my bad. It is SaveSetting.

It's discussed in this paper I referenced earlier: http://www.fmsinc.com/MicrosoftAccess/database-design/temporary-data.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.