Link to home
Start Free TrialLog in
Avatar of cavacasp
cavacasp

asked on

Getting UserName Password

Hello all I need to get the username and password of the current user for a Win 95 or Win 98 or Win NT system.  I need this information to pass it along to the SQL Server as the UID and PWD
Avatar of vmano
vmano

i can give you the code for getting the UserName from NT.
Type the following code into a new module:

' Makes sure all variables are dimensioned in each subroutine.
Option Explicit
 
' Access the GetUserNameA function in advapi32.dll and
' call the function GetUserName.
Declare Function GetUserName Lib "advapi32.dll" Alias  "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
 
' Main routine to Dimension variables, retrieve user name
' and display answer.
Sub Get_User_Name()
     Dim lpBuff As String * 25
     Dim ret As Long, UserName As String
 
' Get the user name minus any trailing spaces found in the name.
     ret = GetUserName(lpBuff, 25)
     UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
 
' Display the User Name
     MsgBox UserName
End Sub

let me find out the other one for you (or) somebody else will give you.
vmano
cavacasp,

Put the following in a sub or function where needed :
-----------------------------------------------------

  Dim strTheString As String
  Dim lngLength As Long
  Dim lngResult As Long
  Dim CurUser As String
 
  lngLength = 199
  strTheString = String(200, 0)
  lngResult = GetUserName(strTheString, lngLength)
  If lngResult <> 0 Then
    CurUser = Left(strTheString, lngLength - 1)
  Else
    CurUser = ""
  End If
 
  MsgBox "Current user = " & CurUser, vbOKOnly + vbInformation, ""


Put the following in a module:
------------------------------

Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
As Long


This should work on Win95, Win98, and WinNT but you should test it.

HATCHET
Avatar of cavacasp

ASKER

I need username and password or it does not help me.
ASKER CERTIFIED SOLUTION
Avatar of Poddy
Poddy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial