I have this that gives me the domain\username of the remote logged on
user:

strComputer = InputBox("Enter the PC-name you want to know who's
logged on at", "Who is logged on?")
if strComputer = "" then
WScript.Echo "Don't you want to know?"
end if

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From
Win32_ComputerSystem")

For Each objItem in colItems
Name = objItem.UserName
wscript.echo name
Next

But i want to output the fullname of the user. I have tried everything
i can think of but only get my own fullname.

I have this that gives me the fullname of the localy logged on user,
but can not get it to work with the other script.

Set WshNetwork = WScript.CreateObject("WScript.Network")
objUserName = WshNetwork.UserName
Set objUser = GetObject("WinNT://" & Name)
wscript.echo objUser.FullName

Any help to get me in the right direction would be much appreciated.

Re: Full name of remote logged on user by Michael

Michael
Fri Jun 15 09:11:09 CDT 2007

> I have this that gives me the fullname of the localy logged on user,
> but can not get it to work with the other script.
>
> Set WshNetwork = WScript.CreateObject("WScript.Network")
> objUserName = WshNetwork.UserName
> Set objUser = GetObject("WinNT://" & Name)
> wscript.echo objUser.FullName

The above gets a local machine account with a username that matches the
domain account username. It doesn't get the user object for the domain
account.

>
> Any help to get me in the right direction would be much appreciated.

Use NameTranslate from the simple domain\username to the full LDAP path,
then use LDAP to a domain user account object...


'Using your own domain\username just to demonstrate...
'
Set net = createobject("wscript.network")

userdomain = net.userdomain
username = net.username

with CreateObject("NameTranslate")
.Init 1, userdomain
.Set 3, userdomain & "\" & username
ldapPath = "LDAP://" & .Get(1)
end with

Set adUser = GetObject(ldapPath)

MsgBox adUser.fullname



--
Michael Harris
Microsoft.MVP.Scripting



Re: Full name of remote logged on user by avregistrera

avregistrera
Fri Jun 15 09:49:22 CDT 2007

Thank you Michael,

It works exacly as i want it now.

strComputer = InputBox("Enter the PC-name you want to know who's
logged on at", "Who is logged on?")
if strComputer = "" then
WScript.Echo "Don't you want to know?"
end if

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From
Win32_ComputerSystem")

For Each objItem in colItems
Name = objItem.UserName
Next

with CreateObject("NameTranslate")
.Set 3, name
ldapPath = "LDAP://" & .Get(1)
end with

Set adUser = GetObject(ldapPath)
MsgBox adUser.fullname