Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting UserName Password

Posted on 1998-11-12
4
Medium Priority
?
223 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

916 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