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?
 
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
 
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Surone1Commented:
try this:

Dim ChangeReg
Set ChangeReg = CreateObject("WScript.Shell")
ChangeReg.RegWrite "HKLM\MyNewKey", 1, "REG_DWORD"
0
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.