Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating key in registry causes garbage

Status
Not open for further replies.

oka97

Programmer
May 25, 2003
28
0
0
GB
Hi, I'm creating a new key with this code:

Public Function CreateNewKey(sNewKeyName As String, lPredefinedKey As Long)

Dim hNewKey As Long 'handle to the new key
Dim lRetVal As Long 'result of the RegCreateKeyEx function

lRetVal = RegCreateKeyEx( _
lPredefinedKey, _
sNewKeyName, _
0&, _
vbNullString, _
REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, _
0&, _
hNewKey, _
lRetVal _
)

RegCloseKey hNewKey

End Function

the caller is:

Temp = CreateNewKey("\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\ForceActiveDesktopOn", HKEY_CURRENT_USER)

But all I get in the root of HKEY_CURRENT_USER is a garbage key :(

Pls help
 
Okay I fixed the problem, u need to set the value of the new key immediately after.

I need to set the new key to a value of either 1 or 0 in hex (type REG_DWORD) but dunno how to do it, the registry keeps saying invalid dword value.
 
Try This

Code:
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_ALL_ACCESS = &H3F

Private Const REG_OPTION_NON_VOLATILE = 0

Key_CreateRoot("\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\ForceActiveDesktopOn")

Public Sub Key_CreateRoot(sNewKeyName As String)
    Dim hNewKey As Long         'handle to the new key
    Dim lRetVal As Long         'result of the RegCreateKeyEx function

    lRetVal = RegCreateKeyEx(HKEY_CURRENT_USER, sNewKeyName, 0&, _
            vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, _
            0&, hNewKey, lRetVal)
    If lRetVal <> 0 Then MsgBox &quot;Error Creating Key&quot;
    RegCloseKey (hNewKey)
End Sub
 
Hi thanks a lot.

When trying to set the reg_dword to 0 or 1 I am baffled!

Temp = SaveRegString(HKEY_CURRENT_USER, &quot;Software\Microsoft\Windows\CurrentVersion\Policies\Explorer&quot;, _
&quot;ForceActiveDesktopOn&quot;, &H0, True)

Instead of giving me 1 it gives me 0x00000030 (48)

I'm confused!
 
Public Enum HKEY_VALUES
CLASSES_ROOT = &H80000000
CURRENT_USER = &H80000001
LOCAL_MACHINE = &H80000002
USERS = &H80000003
End Enum

Public Enum HKEY_TYPES
REGTYPE_STRING = 1
REGTYPE_DWORD = 4
End Enum

Key_Create_Value(LOCAL_MACHINE, &quot;Software\Microsoft\Windows\CurrentVersion\Policies\Explorer&quot;, &quot;ForceActiveDesktopOn&quot;, 1, REGTYPE_DWORD)

Public Sub Key_Create_Value(ByVal sKeyRoot As HKEY_VALUES, sKeyPath As String, sKeyName As String, sKeyValueSetting As Variant, ByVal KeyType As HKEY_TYPES)
Dim lRetVal As Long 'result of the SetValueEx function
Dim hKey As Long 'handle of open key

lRetVal = RegOpenKeyEx(sKeyRoot, sKeyPath, 0, KEY_SET_VALUE, hKey)
If lRetVal <> 0 Then MsgBox &quot;Error Opening Root&quot;

lRetVal = SetValueEx(hKey, sKeyName, KeyType, sKeyValueSetting)
If lRetVal <> 0 Then MsgBox &quot;Error Creating Key Value&quot;
RegCloseKey (hKey)
End Sub
 
I have a compiled library which handles all of my registry stuff...very easy to call and use...it also handles many of the other monotoneus routines I do..There is no malicious code in the DLL. If you'ld like to try it out send me an email robc@rncdevelopment.com and I'll send it to you. Some of the opertations still have a few bugs but for the most part in is in all of my projects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top