Hi,
i use this simple code for retrive the Name and set a label on the main
form.
Bye, Piergi
Declare Function CeRapiUninit Lib "rapi.dll" () As Long
Declare Function CeRapiInitEx Lib "rapi.dll" (pRapiInit As RAPIINIT) As Long
Declare Function CeRegOpenKeyEx Lib "rapi.dll" (ByVal hkey As Long, ByVal
lpSubKey As Long, ByVal ulOptions As Long, ByVal samDesired As Long,
phkResult As Long) As Long
Declare Function CeRegQueryValueEx Lib "rapi.dll" (ByVal hkey As Long, ByVal
lpValueName As Long, ByVal lpReserved As Long, lpType As Long, ByVal lpdata
As Long, lpcbData As Long) As Long
Declare Function CeRegQueryValueExLong Lib "rapi.dll" Alias
"CeRegQueryValueEx" (ByVal hkey As Long, ByVal lpValueName As Long, ByVal
lpReserved As Long, lpType As Long, lpdata As Long, lpcbData As Long) As
Long
Declare Function CeRegQueryValueExString Lib "rapi.dll" Alias
"CeRegQueryValueEx" (ByVal hkey As Long, ByVal lpValueName As Long, ByVal
lpReserved As Long, lpType As Long, ByVal lpdata As Long, lpcbData As Long)
As Long
Declare Function CeRegCloseKey Lib "rapi.dll" (ByVal hkey As Long) As Long
Function ReadCEREgistry() As Long
Dim lRet As Long
Dim phkResult As Long
Dim lpType As Long
Dim lpdata As String
Dim lpvalue As Long
Dim lpcbData As Long
Dim Data As String
Dim key As String
Dim lpdwdisposition As Long
Dim value As String
key = "Ident"
lRet = CeRegOpenKeyEx(HKEY_LOCAL_MACHINE, StrPtr(key), _
0, 0, phkResult)
If lRet <> ERROR_SUCCESS Then
'MsgBox "Failure to open key. Error: " & lret
Main.Label1.Caption = ""
Main.Label2.Caption = "Disconnesso"
Else
value = "Name"
lRet = CeRegQueryValueEx(phkResult, StrPtr(value), _
0, lpType, 0, lpcbData)
Select Case lpType
' -- For strings
Case REG_SZ:
' Allocate string space
lpdata = String(lpcbData, 0)
' Query the string value
lRet = CeRegQueryValueExString(phkResult, StrPtr(value), _
CLng(0), lpType, StrPtr(lpdata), lpcbData)
If lRet = ERROR_SUCCESS Then
Main.Label1.Caption = Left(lpdata, lpcbData - 1)
Main.Label2.Caption = "Connesso"
Else
Main.Label1.Caption = "Senza nome"
Main.Label2.Caption = "Connesso"
lpdata = ""
End If
'-- For DWORDS
Case REG_DWORD:
lRet = CeRegQueryValueExLong(phkResult, StrPtr(value), _
CLng(0), lpType, lpvalue, lpcbData)
If lRet = ERROR_SUCCESS Then MsgBox lpvalue
' -- All other data types not supported
Case Else
lRet = -1
End Select
End If
ReadCEREgistry = lRet
End Function