Solved

Create Registry keys under HKEY_LOCAL_MACHINE in vista/win7.

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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. …
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 demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

13 Experts available now in Live!

Get 1:1 Help Now