Solved

Create Registry keys under HKEY_LOCAL_MACHINE in vista/win7.

Posted on 2010-08-18
3
1,291 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 127
notReplace  challenge 53 142
Annoying "thing" blocks my view 4 117
mapAB Challlenge 35 160
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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