?
Solved

coded works under w98, but not XP

Posted on 2003-02-25
2
Medium Priority
?
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 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