Go Premium for a chance to win a PS4. Enter to Win



Posted on 2000-03-15
Medium Priority
Last Modified: 2012-05-04
i want to create a key in the registry.

i have tried the following:

lRet = RegSetValueEx(hKey, "test", 0, 2, 0, 0)
the problem is, that i don't understand the syntax:
LONG RegSetValueEx(
  HKEY hKey,          // handle to key
  LPCTSTR lpValueName, // value name
  DWORD Reserved,      // reserved
  DWORD dwType,        // value type
  CONST BYTE *lpData,  // value data
  DWORD cbData        // size of value data
i want to create the complete key with the entry clsid with the value:

maybe somebody can send me an example
thanks very much
Question by:fragen
  • 2
LVL 28

Expert Comment

ID: 2621631
LVL 28

Accepted Solution

Ark earned 150 total points
ID: 2621695
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long

Private Const REG_SZ As Long = 1
Private Const REG_DWORD As Long = 4
Private Const HKEY_LOCAL_MACHINE As Long = &H80000002

Public Function regCreate_A_Key(ByVal hKey As Long, ByVal sRegKeyPath As String)
'Function to create a new key
'regCreate_A_Key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PROTOCOLS\Handler\mailto"
  Dim lKeyHandle As Long
  Dim lRet As Long
  lRet = RegCreateKey(hKey, sRegKeyPath, lKeyHandle)
  lRet = RegCloseKey(lKeyHandle)
End Function

Public Sub regCreate_Key_Value(ByVal hKey As Long, ByVal sRegKeyPath As String, ByVal sRegSubKey As String, vRegData As Variant)
' Function to wtite a value
' Call:
'regCreate_Key_Value "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PROTOCOLS\Handler\mailto", "CLSID", "{3050f3DA-98B5-11CF-BB82-00AA00BDCE0B}"  
  Dim lKeyHandle As Long
  Dim lRet As Long
  Dim lDataType As Long
  Dim lKeyValue As Long
  Dim sKeyValue As String
  If IsNumeric(vRegData) Then
      lDataType = REG_DWORD
      lDataType = REG_SZ
  End If
  lRet = RegCreateKey(hKey, sRegKeyPath, lKeyHandle)
  Select Case lDataType
         Case REG_SZ:       ' String
              sKeyValue = Trim(vRegData) & Chr(0)
              lRet = RegSetValueEx(lKeyHandle, sRegSubKey, 0&, lDataType, ByVal sKeyValue, Len(sKeyValue))
         Case REG_DWORD:    ' Integer
              lKeyValue = CLng(vRegData)
              lRet = RegSetValueEx(lKeyHandle, sRegSubKey, 0&, lDataType, lKeyValue, 4&)
  End Select
  lRet = RegCloseKey(lKeyHandle)
End Sub

But, IMHO, more easy way is using Windows Scripting Host

Paste following code at form code section
WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PROTOCOLS\Handler\mailto\CLSID", "{3050f3DA-98B5-11CF-BB82-00AA00BDCE0B}"

LVL 28

Expert Comment

ID: 2621714
You can find more about working with registry using windows scripting host at http://support.microsoft.com/support/kb/articles/Q244/6/75.ASP
LVL 10

Expert Comment

ID: 2623591
Last 3 Grade(s) Given:  
A B B  
Question Grading Record:  
3 / 8  

Looks like fragen is good at Fragen but not so good at Antworten.


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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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

916 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