• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

RegSetValueEx

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
fragen
Asked:
fragen
  • 2
1 Solution
 
AzraSoundCommented:
0
 
ArkCommented:
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
 
ArkCommented:
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
 
caraf_gCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now