Writing DWORD Registry Values

What I have to do to write DWORD Registry Values? There is a Method KeyType for RegistryItem but in the Documentation there is no hint where and how to implement this and within IDE this method does not show up. I have a method for writing registry values but my written values always end up as string values. I would like to use optional parameter namend “RegType” as KeyType but I do not know where I could set my RegItem. Could anybody help me out please? Thanx in advance!


Function WriteRegistry(Folder As String, Key As String, NewValue as Variant, optional RegType as Integer = 0) as Boolean

  Dim myRegItem As RegistryItem
  Dim found As Boolean = true
  Dim elements(-1), path As String
  
  try
    
    elements = folder.split("\")
    
    For i As Integer = 0 To Elements.Ubound
      
      path = path + elements(i) + "\"
      
      Try
        
        myRegItem = New RegistryItem(path, True)
        
      Catch err As RegistryAccessErrorException
        
        found = False
        Exit
        
      End Try
      
    Next
    
  Finally
    
  end try
  
  If found And myRegItem <> Nil Then
    
   // How to set DWORD Values ?
    myRegItem.value(key) = NewValue
    return true
  Else
    return false
  End If

end function

If you parameter NewValue is being passed in via an integer type variable, then I would expect it to be stored as a dword ( assuming the reg. entry did not already exist as a string ).

In other words, what I see is…

dim myValyeInt as integer = 123
// Save as dword…
myRegItem.value(key) = myValueInt

dim myValueStr as string = “ABC”
// Save as string
myRegItem.value(key) = myValueStr

Ah thank you Chris. This works! Thought I have to define and convert types first.

An item already exists and I want to modify. I am getting exeption error.

myRegItem.value(“fontSize”) = 12

does not overwrite the old value. Can anyone suggest how to modify registry values?

[quote=221431:@Siva K]An item already exists and I want to modify. I am getting exeption error.

myRegItem.value(“fontSize”) = 12

does not overwrite the old value. Can anyone suggest how to modify registry values?[/quote]

What is the path of that registry value ?

Here is the registry path:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mysoftware

fontSize is REG_DWORD. I am able to read the value to verify that I am accessing the right location.

Windows 7, 64 bit machine.

[quote=221444:@Siva K]Here is the registry path:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mysoftware

fontSize is REG_DWORD. I am able to read the value to verify that I am accessing the right location.

Windows 7, 64 bit machine.[/quote]

If you do not have the proper access privileges, you will get a RegistryAccessErrorException
http://documentation.xojo.com/index.php/RegistryAccessErrorException

I am moving my settings to
HKEY_CURRENT_USER\Software\Mysoftware and it now works.

I can’t thank microsoft enough … ahhh… :slight_smile: