I am trying to retrieve a Windows NT user's password to use it for verifying a SQL Server login. I have the code that accesses the API, but it is not executing the callback function that actullay retrievs the info.
Here is th code....
'*************************
**********
**********
**
'* Function to Get The UserName From Windows NT (in my form)
'*************************
**********
**********
**
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'******************
'* Code in my form
'*****************
'Get the Password from Windows NT
Dim i As Integer
Dim s As String
Dim l As Long
Dim b As Byte
b = &HFF
i = 0
l = 0
s = ""
'?????????????why does this not execute the callback function?????????????
Call WNetEnumCachedPasswords(s,
i, b, AddressOf callback, l)
txtPassword.Text = goConnect.NTPassword
'connect to SQL Server
If SQLTestConnection Then
MsgBox "Test Connection to SQL Server Successful", vbInformation, Me.Caption
'display the table list frame
Call FormToggle
fraSQLServer.Visible = False
'load the grid with table names (if not already)
If lstTables.ListCount = 0 Then
For intIndex = 0 To goConnect.TableCount - 1
lstTables.AddItem (goConnect.TableNames(intI
ndex, 0))
Next intIndex
End If
End If
'*************************
'* Code From a BAS Module
'*************************
'*************************
*****
'* Gets the User's NT Password
'*************************
*****
'undocumented function in mpr.dll
Declare Function WNetEnumCachedPasswords Lib "mpr.dll" (ByVal s As String, ByVal i As Integer, ByVal b As Byte, ByVal proc As Long, ByVal l As Long) As Long
'purpose: to parse the .PWL file of the currently logged on user
'platform: win '95 (ms networking, password caching enabled)
'language: vb 5.0 sp2
'author: todd harmon <tharmon@gyver.com>
'date: 9/16/1998
'comments: the mpr.dll has many functions that are poorly documented,
' this is my attemped at unraveling one of those functions
' for visual basic programmers
'
'this sample program is provided "as is"!
'use at your own risk!
'comments/questions are welcome, see e-mail address above
'this structure is returned by the call to WNetEnumCachedPasswords
Type PASSWORD_CACHE_ENTRY
cbEntry As Integer 'size of this returned structure in bytes
cbResource As Integer 'size of the resource string, in bytes
cbPassword As Integer 'size of the password string, in bytes
iEntry As Byte 'entry position in PWL file
nType As Byte 'type of entry
abResource(1 To 1024) As Byte 'buffer to hold resource string, followed by password string
'should this be bigger?
End Type
Public Function callback(x As PASSWORD_CACHE_ENTRY, ByVal lSomething As Long) As Integer
'callback routine for WNetEnumCachedPasswords results
Dim i As Integer
Dim s As String
s = "Type: " & x.nType
'1 = domains?
'4 = mail/mapi clients?
'6 = RAS entries?
'19 = iexplorer entries?
s = s & " Rsrc: "
For i = 1 To x.cbResource
If x.abResource(i) <> 0 Then 'nulls don't display nicely
s = s & Chr(x.abResource(i))
Else
s = s & " "
End If
Next i
s = s & " Pwd: "
For i = x.cbResource + 1 To (x.cbResource + x.cbPassword)
If x.abResource(i) <> 0 Then 'nulls don't display nicely
s = s & Chr(x.abResource(i))
Else
s = s & " "
End If
Next i
goConnect.NTPassword = s
callback = True
End Function