?
Solved

coded works under w98, but not XP

Posted on 2003-02-25
2
Medium Priority
?
282 Views
Last Modified: 2010-05-18
the function "RegCreateKeyEx" always returns error code 6 under XP, but works under W98.

Public Function createKey(Key As String, _
  Optional path As String = "Software", _
  Optional root As Long = HKEY_LOCAL_MACHINE) As Boolean
 
  Dim KeyRoot As Long
  If RegOpenKeyEx(root, path, 0, KEY_READ, KeyRoot) = 0 Then
   
    RegCloseKey (KeyRoot)
   
    Dim hKey As Long, Back As Long
    Dim SA As SECURITY_ATTRIBUTES
    Dim Result As Long
    Result = RegCreateKeyEx(KeyRoot, Key, 0, vbNull, 0, KEY_WRITE, SA, hKey, Back)
    If Result = 0 Then
    'If RegCreateKeyEx(KeyRoot, Key, 0, 0, 0, KEY_WRITE, 0, hKey, Back) = 0 Then
      createKey = True
      RegCloseKey (hKey)
    Else
      MsgBox "return value from create reigstry key function: " & CStr(Result)
    End If
 
  End If
End Function

0
Comment
Question by:hongtaoc
2 Comments
 
LVL 5

Accepted Solution

by:
JMoon5FTM earned 40 total points
ID: 8018521
Maybe:

1)  KEY_READ above should be KEY_WRITE, if you are making changes?

2)  your user account doesn't have permissions on that branch of the registry?
0
 

Author Comment

by:hongtaoc
ID: 8018663
thanks,

but i'd found the problem by myself. it's the problem of the SECURITY_ATTRIBUTES definition

in almost all the examples about the registry access, the definition of SECURITY_ATTRIBUTES is :

Private Type SECURITY_ATTRIBUTES
  Length As Long
  SecurityDescriptor As Long
  InheritHandle As Long
End Type

it's not problem in W98, but in XP (should be same in W2K), the proper definition should be:

Private Type SECURITY_ATTRIBUTES
  Length As Long
  SecurityDescriptor As Long
  InheritHandle As Boolean '!!! LONG
End Type


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

616 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