Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Registry DWORD Values?

Status
Not open for further replies.

mattp14

Programmer
Apr 8, 2005
35
US
I got such a helpful and professional response from my last question here... i thought i'd come back :)

My question this time is in regards to creating and modifying dword values in the windows registry. I can use the following function to write string values, but I need to be able to write dwords.

Imports Microsoft.Win32

Public Function setRegValue(ByVal hive As String, ByVal path As String, ByVal value As String, ByVal data As Object)
Dim regKey As RegistryKey

'Determine the hive and open/create the designated path
Select Case hive.ToLower()
Case "classesroot"
regKey = Registry.ClassesRoot.CreateSubKey(path)
Case "currentconfig"
regKey = Registry.CurrentConfig.CreateSubKey(path)
Case "currentuser"
regKey = Registry.CurrentUser.CreateSubKey(path)
Case "dyndata"
regKey = Registry.DynData.CreateSubKey(path)
Case "localmachine"
regKey = Registry.LocalMachine.CreateSubKey(path)
Case "performancedata"
regKey = Registry.PerformanceData.CreateSubKey(path)
Case "users"
regKey = Registry.Users.CreateSubKey(path)
End Select

'Create the value and close the key
regKey.SetValue(value, data)
regKey.Close()
End Function


Any thoughts? Thanks again!!
 
You have to cast the value you are writing as a numeric type.
For example
Code:
if isnumeric(data)
 regKey.SetValue(value, cdbl(data))
end if

You could use cint() or change the data value to a decimal value. Just so long as its numeric you will get a DWORD


Sweep
...if it works dont mess with it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top