Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Retrieving Domain of Logged in user

Posted on 2003-03-14
4
Medium Priority
?
257 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
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 23 hours left to enroll

564 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