?
Solved

Registry Question

Posted on 1998-07-08
2
Medium Priority
?
147 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
  • 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…
Suggested Courses
Course of the Month16 days, 23 hours left to enroll

862 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