Link to home
Start Free TrialLog in
Avatar of AutomateMyOffice
AutomateMyOffice

asked on

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.
Avatar of Luke Chung
Luke Chung
Flag of United States of America image

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
Avatar of AutomateMyOffice
AutomateMyOffice

ASKER

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.
try this:

Dim ChangeReg
Set ChangeReg = CreateObject("WScript.Shell")
ChangeReg.RegWrite "HKLM\MyNewKey", 1, "REG_DWORD"
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.
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.
SOLUTION
Avatar of Surone1
Surone1
Flag of Suriname image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial