Solved

Create Registry keys under HKEY_LOCAL_MACHINE in vista/win7.

Posted on 2010-08-18
3
1,285 Views
Last Modified: 2012-05-10
Hi,
    I have a piece of VB6 code that writes string data under HKEY_LOCAL_MACHINE using RegCreateKeyEx API. this works well under XP but under vista/win7 it does not write. I tried "run as administrator" but even then it does not work. With UAC off it works, except in 2 of the 7 PCs that I tried in. I also tried the following code I found on microsoft site

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &    strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\NewKey"
objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath

but this also does not work.

What would be a foolproof method of writing the data.

Thanks & regards,

DJ
0
Comment
Question by:djawahar
  • 2
3 Comments
 
LVL 41

Expert Comment

by:graye
ID: 33500742
This still sounds like it's a UAC issue...  
The HKLM\Software key in WinV/Win7 requires administrator rights.   Are you sure that running the application with "Run As Administrator" doesn't work?
0
 

Author Comment

by:djawahar
ID: 33508172
Hi graye,
      I just checked again. the 2 machines where I have problem even when I use "Run as Administrator" are running 64 BIT versions of Win 7. I think this has something to do with 64BIT rather than UAC. What I dont understand is that RegCreateKeyEx exits without any error code. It makes it look as if the key has been created.

Thanks & regards,

DJ
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 33509891
Ah yes... there is registry virtualization going on with 64-bit versions of the OS.
You'll have to use the low-level API routines with the KEY_WOW64_64KEY parameter to get access to the 64-bit keys from a 32-bit application
This article explains it all:  http://msdn.microsoft.com/en-us/library/ms724072(v=VS.85).aspx
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question