[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Registry Question

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 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…
Suggested Courses

649 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