Solved

RegSetValueEx

Posted on 2000-03-15
4
402 Views
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:

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PROTOCOLS\Handler\mailto]
"CLSID"="{3050f3DA-98B5-11CF-BB82-00AA00BDCE0B}"
 
maybe somebody can send me an example
thanks very much
fragen
0
Comment
Question by:fragen
  • 2
4 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2621631
0
 
LVL 27

Accepted Solution

by:
Ark earned 50 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
'Call:
'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
  Else
      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}"

Cheers
0
 
LVL 27

Expert Comment

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

Expert Comment

by:caraf_g
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.

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

776 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