Ce.NET Registry

Ministry

Member
Joined
Apr 7, 2005
Messages
12
Programming Experience
1-3
I need to check for the prescence of a key in the ce.net registry. How i can access this? Either a program like regedit or in code?

Thanks
 

Sylpheed

Member
Joined
Jun 30, 2005
Messages
5
Programming Experience
3-5
I don't think CE has a regedit software.. not that i know off.

what i use is OpenNETCF.Win32 Do a search on google for this.
 

tuanhawaii

Member
Joined
Nov 10, 2005
Messages
12
Programming Experience
1-3
CE does support registry. Here is the module that you can use to read and write registry

Public Declare Function RegOpenKeyEx Lib "Coredll" Alias "RegOpenKeyExW" (ByVal hKey As Integer, ByVal lpSubKey As String, ByVal ulOptions As Integer, ByVal samDesired As Integer, ByRef phkResult As Integer) As Integer
Public Declare Function RegQueryValueEx Lib "Coredll" Alias "RegQueryValueExW" (ByVal hKey As Integer, ByVal lpValueName As String, ByVal lpReserved As Integer, ByRef lpType As Integer, ByVal lpData As String, ByRef lpcbData As Integer) As Integer
Public Declare Function RegCloseKey Lib "Coredll" (ByVal hKey As Integer) As Integer
Public Declare Function RegCreateKeyEx Lib "Coredll" Alias "RegCreateKeyExW" (ByVal hKey As Integer, ByVal lpSubKey As String, ByVal Reserved As Integer, ByVal lpClass As String, ByVal dwOptions As Integer, ByVal samDesired As Integer, ByRef lpSecurityAttributes As Integer, ByRef phkResult As Integer, ByRef lpdwDisposition As Integer) As Integer
Public Declare Function RegSetValueEx Lib "Coredll" Alias "RegSetValueExW" (ByVal hKey As Integer, ByVal lpValueName As String, ByVal Reserved As Integer, ByVal dwType As Integer, ByVal lpData As String, ByVal cbData As Integer) As Integer ' Note that if you declare the lpData parameter as String, you must pass it By Value.

Public Const SYNCHRONIZE As Integer = &H100000
Public Const KEY_NOTIFY As Short = &H10S
Public Const READ_CONTROL As Integer = &H20000
Public Const STANDARD_RIGHTS_READ As Integer = &H20000
Public Const KEY_QUERY_VALUE As Short = &H1S
Public Const KEY_ENUMERATE_SUB_KEYS As Short = &H8S
Public Const KEY_SET_VALUE As Short = &H2S
Public Const ERROR_FILE_NOT_FOUND As Short = 2
Public Const ERROR_SUCCESS As Short = 0
Public Const REG_OPTION_NON_VOLATILE As Short = 0
Public Const REG_SZ As Short = 1
Public Const HKEY_LOCAL_MACHINE As Integer = &H80000002

Public Function CEGetSetting(ByRef strError As Object, ByVal APPNAME As String, ByVal Section As String, ByVal Key As String, ByRef Setting As String) As Boolean

On Error Resume Next

Dim lngSize As Integer
Dim hlngSubKey As Integer
Dim lngType As Integer
Dim lngResult As Integer
Dim Key_Read As Integer
Dim SubKey As String

'False until proven true...
CEGetSetting = False

Key_Read = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))

'Fill the "Setting" parameter with 256 chr(0)'s
lngSize = 256
Setting = New String(Chr(0), lngSize)
SubKey = APPNAME & "\" & Section

'Open the registry key and find a handle to the sub key
'It is always under HKEY_LOCAL_MACHINE
'Return hlngSubKey, lngResult indicates success or failure
lngResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SubKey, 0, Key_Read, hlngSubKey)

If (lngResult <> ERROR_SUCCESS) Then
'UPGRADE_WARNING: Couldn't resolve default property of object strError. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
strError = "CEGetSetting: Unable to open the registry sub-key '" & SubKey & "'."
Exit Function
End If

'Try to read the value of the item
'Pass in hlngSubKey and the Key we are looking for.
'Setting is 256 chr(0) on the way in (Byref).
'Return lngType, strItemValue, lngSize
lngResult = RegQueryValueEx(hlngSubKey, Key, 0, lngType, Setting, lngSize)

If (lngResult = ERROR_SUCCESS) And (lngType = 1) Then
'OK - the Setting came back but it is 256 chars long, padded with chr(0).
Setting = Setting.Substring(0, lngSize)
Else
'Error...
'Close the registry before we exit
lngResult = RegCloseKey(hlngSubKey)
lngResult = RegCloseKey(HKEY_LOCAL_MACHINE)
'UPGRADE_WARNING: Couldn't resolve default property of object strError. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
strError = "CEGetSetting: Unable to read the registry value for '" & Key & "'. (" & lngResult & ")."
Exit Function
End If

'All is well if we got this far. Close the keys.
lngResult = RegCloseKey(hlngSubKey)
lngResult = RegCloseKey(HKEY_LOCAL_MACHINE)

'UPGRADE_WARNING: Couldn't resolve default property of object strError. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
strError = ""
CEGetSetting = True

End Function

Public Function CESaveSetting(ByRef strError As String, ByVal APPNAME As String, ByVal Section As String, ByVal Key As String, ByVal Setting As String) As Boolean

Dim TempSetting As String
Dim hlngSubKey As Integer
Dim lngResult As Integer
Dim lngDisposition As Integer
Dim SubKey As String

'CESaveSetting(strError As String, ByVal AppName As String, ByVal Section As String,
'ByVal Key As String, ByVal Setting As String) As Boolean

'Public Function SaveSetting(strError As String, ByVal strSubKey As String,
'ByVal strItemName As String, ByVal Setting As String) As Boolean

'SOFTWARE\pktSoft\TTDS
'Settings
'DatabasePath
'ce

'False until proven true
CESaveSetting = False

'Make sure the values are not empty
If Trim(APPNAME) = "" Or Trim(Section) = "" Or Trim(Key) = "" Then
strError = "CESaveSetting: The spplication name, section and key must be set."
Exit Function
End If

'Null terminate the item value string
TempSetting = Setting & Chr(0)
SubKey = APPNAME & "\" & Section

'Create the registry key and set a handle to the sub key
lngResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, SubKey, 0, vbNullString, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, 0, hlngSubKey, lngDisposition)
If lngResult <> ERROR_SUCCESS Then
lngResult = RegCloseKey(hlngSubKey)
lngResult = RegCloseKey(HKEY_LOCAL_MACHINE)
strError = "CESaveSetting: Unable to create the registry sub-key '" & SubKey & "'."
Exit Function
End If

'Try to set the value of the item
'Only works for strings!
'The declare statement must be altered for other datatypes!
lngResult = RegSetValueEx(hlngSubKey, Key, 0, REG_SZ, TempSetting, 2 * Len(TempSetting))
If lngResult <> ERROR_SUCCESS Then
strError = "CESaveSetting: Unable to set the registry value '" & Key & "-" & Setting & "'."
Exit Function
End If

'All is well if we got this far. Close the keys.
lngResult = RegCloseKey(hlngSubKey)
lngResult = RegCloseKey(HKEY_LOCAL_MACHINE)

'Set the returning values
strError = ""
CESaveSetting = True

End Function
 

tim_rutter

New member
Joined
Sep 14, 2006
Messages
3
Programming Experience
Beginner
Personally I found downloading and installing Windows Embedded C++ most useful. It has a remote registry editor and various other tools. Very useful and its free.
 
Top Bottom