Solved

Registry Question

Posted on 1998-07-08
2
142 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 200 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

Independent Software Vendors: 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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

726 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