Solved

Getting UserName Password

Posted on 1998-11-12
4
216 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

864 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

16 Experts available now in Live!

Get 1:1 Help Now