Solved

Getting UserName Password

Posted on 1998-11-12
4
215 Views
Last Modified: 2010-04-30
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
0
Comment
Question by:cavacasp
4 Comments
 
LVL 3

Expert Comment

by:vmano
ID: 1444581
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
0
 
LVL 3

Expert Comment

by:HATCHET
ID: 1444582
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
0
 

Author Comment

by:cavacasp
ID: 1444583
I need username and password or it does not help me.
0
 
LVL 2

Accepted Solution

by:
Poddy earned 70 total points
ID: 1444584
Use integrated security on your SQL Server.

The only way to get the password is to get the user to enter it
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now