Solved

Create Registry keys under HKEY_LOCAL_MACHINE in vista/win7.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 90
Define unique primary key 9 89
has77  challenge 9 73
wordmultiple challenge 12 121
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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 …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

864 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now