• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 719
  • Last Modified:

Looking for current logon user name

Is there a code that look for current logon user name?
0
dongocdung
Asked:
dongocdung
3 Solutions
 
Chris BottomleyCommented:
Try the following:

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

Open in new window

0
 
bsharathCommented:
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
 
Richard KreidlSoftware DeveloperCommented:
Try this:
Dim  usr = Environ("username")

msgbox(usr)
0
 
dongocdungAuthor Commented:
Good article
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now