Solved

Looking for current logon user name

Posted on 2008-10-28
4
711 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
Comment Utility
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
Comment Utility
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
Comment Utility
Try this:
Dim  usr = Environ("username")

msgbox(usr)
0
 

Author Comment

by:dongocdung
Comment Utility
Good article
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

744 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