Solved

RegSetValueEx

Posted on 2000-03-15
4
403 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
[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
4 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2621631
0
 
LVL 28

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 28

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

691 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