Solved

Looking for current logon user name

Posted on 2008-10-28
4
713 Views
Last Modified: 2011-09-20
Is there a code that look for current logon user name?
0
Comment
Question by:dongocdung
4 Comments
 
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 100 total points
ID: 22822245
Try the following:

Chris
dim wshell
 
set wshell = createobject("wscript.shell")
wscript.echo wshell.expandenvironmentstrings("%username%")

Open in new window

0
 
LVL 11

Assisted Solution

by:bsharath
bsharath earned 100 total points
ID: 22823901
Is this to find who is currentl logged in to a machine.?
then try this
Code from EE...
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process")
loggedin = "nobody"
For Each objProcess in colProcessList
    if instr(objProcess.Name, "explorer") <> 0 then
        colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
        loggedin =  strUserDomain & "\" & strNameOfUser
        exit for
   end if
Next
WScript.Echo loggedin & " logged in"

Open in new window

0
 
LVL 2

Accepted Solution

by:
rkckjk earned 300 total points
ID: 22824518
Try this:
Dim  usr = Environ("username")

msgbox(usr)
0
 

Author Comment

by:dongocdung
ID: 22825146
Good article
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Write data from SQL to CSV file - position 1 58
Microsoft Access combo box help 2 44
How to Add / Edit Windows Menu 4 59
Protecting vb6 & .Net code Obfuscation 18 121
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…
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 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…
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…

813 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