Solved

Domain Name

Posted on 2001-06-25
1
126 Views
Last Modified: 2010-05-02
Hi,
Can anybody help me in retrieving the username and the DOMAIN of the user on a Win95 Environment.

Thanx
Harish
0
Comment
Question by:harishsc
1 Comment
 
LVL 27

Accepted Solution

by:
Ark earned 50 total points
Comment Utility
Hi
You can do it with Windows Scripting Host. Unfortunatelly, WSH under w95 don't show UserDomain (see http://support.microsoft.com/support/kb/articles/Q188/6/02.asp).

So, code:

Private Sub Command1_Click()
  Dim oNetwork As Object
  Dim oShell As Object
  Dim sDomain As String, sUserName As String, sCompName As String
  Const LogDomstr = "HKLM\SYSTEM\CurrentControlSet\Services\MSNP32\NetworkProvider\AuthenticatingAgent"
  Const Workgroupstr = "HKLM\SYSTEM\CurrentControlSet\Services\VxD\VNETSUP\Workgroup"
  Set oNetwork = CreateObject("WScript.Network")
  Set oShell = CreateObject("WScript.Shell")
  sUserName = oNetwork.UserName
  sCompName = oNetwork.ComputerName
  sDomain = oShell.RegRead(LogDomstr)
  If (sDomain = "") Then sDomain = oShell.RegRead(Workgroupstr)
  Debug.Print sUserName, sDomain, sCompName
  Set oShell = Nothing
  Set oNetwork = Nothing
End Sub

Cheers
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…

728 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

10 Experts available now in Live!

Get 1:1 Help Now