Link to home
Start Free TrialLog in
Avatar of djawahar
djawahar

asked on

Create Registry keys under HKEY_LOCAL_MACHINE in vista/win7.

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
Avatar of graye
graye
Flag of United States of America image

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?
Avatar of djawahar
djawahar

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America 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