ScoobyNet.com - Subaru Enthusiast Forum

ScoobyNet.com - Subaru Enthusiast Forum (https://www.scoobynet.com/)
-   Computer & Technology Related (https://www.scoobynet.com/computer-and-technology-related-34/)
-   -   Get users name from computer name? (https://www.scoobynet.com/computer-and-technology-related-34/588646-get-users-name-from-computer-name.html)

bioforger 05 March 2007 03:37 PM

Get users name from computer name?
 
As above is it possible?

I can get the users ID on our network, using nbtstat -a computername.

But I need the users real name, any help appreciated thanks.

David_Wallis 05 March 2007 07:54 PM

try this

Code:


' ***********************************************************************************************
' RetrieveLoggedOnUsers.vbs - DWallis 05/03/07
'
' Usage Cscript //NoLogo RetrieveLoggedOnUsers.Vbs computer1Name Computer2Name
' ***********************************************************************************************
 
' ***********************************************************************************************
' Check Script is being run with CSCRIPT
' ***********************************************************************************************
   
If UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" Then
    strPath = Wscript.ScriptFullName
        Wscript.Echo "This script should be run under CScript." & vbCrLf & vbCrLf & "Re-Starting Under CScript"
    strCommand = "%comspec% /K cscript //NOLOGO " & Chr(34) & strPath & chr(34)
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run(strCommand)
    Wscript.Quit
End If

' ***********************************************************************************************
' Check Arguments Passed (Computer Names), If none are passed then default to local machine
' ***********************************************************************************************

If Wscript.Arguments.Count = 0 Then
    arrComputers = Array(".")
Else
    Dim arrComputers()
    For i = 0 to Wscript.Arguments.Count - 1
        Redim Preserve arrComputers(i)
        arrComputers(i) = Wscript.Arguments(i)
    Next
End If
 
For Each strComputer in arrComputers
        Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
 
        For Each objComputer in colComputers
                    Wscript.Echo "ComputerName: " & strComputer & " UserName: " & objComputer.UserName
        Next
Next


jowl 05 March 2007 07:55 PM

I just use Kix

Would that be any could

David_Wallis 05 March 2007 08:10 PM

Kix is just a scripting language, you would still need to query the remote machine to find the users that have an explorer.exe process running or using wmi as I did..

I can also use kix if you want it writing in that, but that involves a download, where as cscript / wscript shouldnt.

David

bioforger 05 March 2007 10:57 PM

That looks awesome Dave, but as I'm a complete coding noob, how do I run it? :)

Just save it as a .vbs and run it? Or something (cscript) else? Thanks.

David_Wallis 06 March 2007 11:53 AM

save it as a vbs file, for example RetrieveLoggedOnUsers.Vbs

Then in a command prompt do:

Cscript //NoLogo RetrieveLoggedOnUsers.Vbs computerName AnotherComputer Name


You can pass either one computer name or multiple computernames.

You will need admin rights on the remote pc though.

David

mike1210 06 March 2007 11:57 AM

Ace, works a treat:thumb:

jowl 06 March 2007 06:44 PM


Originally Posted by David_Wallis (Post 6720436)
Kix is just a scripting language, you would still need to query the remote machine to find the users that have an explorer.exe process running or using wmi as I did..

I can also use kix if you want it writing in that, but that involves a download, where as cscript / wscript shouldnt.

David

Ah, sorry didn't read the original question correctly!

bioforger 06 March 2007 08:39 PM


Originally Posted by David_Wallis (Post 6722295)
save it as a vbs file, for example RetrieveLoggedOnUsers.Vbs

Then in a command prompt do:

Cscript //NoLogo RetrieveLoggedOnUsers.Vbs computerName AnotherComputer Name


You can pass either one computer name or multiple computernames.

You will need admin rights on the remote pc though.

David

DOH! completely missed the usage line.

It works a treat thanks alot Dave :thumb:

David_Wallis 06 March 2007 08:52 PM

No probs.


All times are GMT +1. The time now is 06:31 AM.


© 2024 MH Sub I, LLC dba Internet Brands