Solved

Looking for current logon user name

Posted on 2008-10-28
4
714 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

860 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