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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem Reading Registry on XP

Status
Not open for further replies.

NYGirl75

Programmer
Jun 3, 2003
1
US
I have ran across an issue it appears is XP related. On my NT machine I can read the registry fine, however the same function returns a blank on an XP machine. The specifc part that is not returning a value on XP but is on NT is the RegQueryValueEXString function:
sValue = String(cch, 0)

lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, _ sValue, cch)

If lrc = ERROR_NONE Then
vValue = Left$(sValue, cch - 1)
Else vValue = Empty
End If
The vValue parameter is blank now is XP but the same code reads the registry fine and fills this variable in NT. Anyone have any suggestions? Thanks!!
 
I had also detected this problem and found a work around.
Use GetUserNameA instead of RegQueryValueExString.

Private Declare Function GetUserNameA Lib "advapi32.dll" (ByVal lpBuffer As String, ByRef nSize As Long) As Long

and do something like this:
InfoSize = 128 'set max length to retrieve
Info = String$(InfoSize + 1, 0) 'allocate buffer

ret = GetUserNameA(Info, InfoSize) 'get value

If ret <> 0 Then 'success?
USERNAME = Left$(Info, InfoSize - 1)
'return value
End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top