?
Solved

Registry Question

Posted on 1998-07-08
2
Medium Priority
?
144 Views
Last Modified: 2010-05-03
I need code that creates a key in the registry.  However, one of the keys that it gets created under must be a command line variable.

The key it must create is:
HKEY_USERS\ * \Software\Microsoft\EXCHANGE

where the '*' is the command line parameter passed.

The key that it creates should be empty.

I need VB5 Source Code.  No OCX's should be used either.
0
Comment
Question by:johnstar
[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
2 Comments
 
LVL 4

Accepted Solution

by:
tomook earned 400 total points
ID: 1465255
This can all be done with API calls, so no problem. Error handling and other niceties are left up to you.

Option Explicit

Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Public Const MAX_PATH = 260
Public Const SYNCHRONIZE = &H100000
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const READ_CONTROL = &H20000
Public Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Public Const ERROR_SUCCESS = 0&
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const REG_OPTION_NON_VOLATILE = 0       ' Key is preserved when system is rebooted
Public Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Public Const REG_CREATED_NEW_KEY = &H1                      ' New Registry Key created
Public Const REG_OPENED_EXISTING_KEY = &H2                      ' Existing Key opened
Public Const STANDARD_RIGHTS_ALL = &H1F0000

Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
End Type

Function CreateMyKey(ByVal MyPart As String) As Long    
    Dim lReturn As Long
    Dim hKey As Long
    Dim lpSubKey As String
    Dim Reserved As Long
    Dim lpClass As String
    Dim samDesired As Long
    Dim phkResult As Long
    Dim lpdwDisposition As Long
    Dim bTmp1 As Boolean
    Dim lpSecurityAttributes As SECURITY_ATTRIBUTES
    Dim dwOptions As Long

    '   Initialize Objects
    hKey = HKEY_USERS
    lpSubKey = MyPart & "\Software\Microsoft\EXCHANGE"
    Reserved = 0
    lpClass = ""
    samDesired = KEY_WRITE
    dwOptions = REG_OPTION_NON_VOLATILE
    With lpSecurityAttributes
        .nLength = 0
        .lpSecurityDescriptor = 0
        .bInheritHandle = 0
    End With
   
    lReturn = RegCreateKeyEx(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition)
   
    If lReturn = REG_CREATED_NEW_KEY Then
        ' Created new key
    ElseIf lReturn = REG_OPENED_EXISTING_KEY Then
        ' Key already existed.
    End If
   
    lReturn = RegCloseKey(phkResult)
End Function

0
 
LVL 4

Expert Comment

by:tomook
ID: 1465256
I should also note that this will work on 95 and NT.
0

Featured Post

Technology Partners: 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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

777 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