?
Solved

Retrieving Domain of Logged in user

Posted on 2003-03-14
4
Medium Priority
?
249 Views
Last Modified: 2012-06-27
After countless searching I still can't find the answer.

The problem is this. I am writing a VB program that needs to know who the user is that is logged into windows. I can get the username just fine using the Windows API GetUserNameA, however I need the domain name of the account also. The GetUserNameA only returns the Username of the account. The domain is necessary part so the program can run properly since it will connect to a SQL database using Windows NT authentication.

Only requirement, can not use Windows Scripting Host, since the exe will be ran from a network directory I can not take the chance on whether or not the machine has WSH installed (or some other non common DLL).

Thanks.
0
Comment
Question by:SpprtMechanic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 500 total points
ID: 8137358
Private Sub Command1_Click()
MsgBox Environ("UserDomain")
End Sub
0
 

Author Comment

by:SpprtMechanic
ID: 8137455
Thanks Vinny, that worked wonderful. One quick question, where can I find what other values are available in with the Environ() function? Microsoft's web site only discusses it in general terms and gives no specifics about it.

Thanks.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8137481
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8137489
This will loop through the available variables and their values:

Private Sub Command1_Click()
For x = 1 To 80
MsgBox Environ(x)
Next x
End Sub
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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