Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding out Who is logged into a Machine

Status
Not open for further replies.

Leighton21

Technical User
Dec 17, 2001
83
AU
Hi All,

Definately new to SMS however I am wondering if SMS is able to detect who is logged into a particular mahine at any one point

Regards
 
Open SMS and locate the machine you are looking at. Double click on the computer name and within that box it will state who last logged onto the machine. Personally I would rather download an external tool such as pstools because they work better at real time. SMS information can be several hours old depending on the size of you network.

If anyone calls and says "I know a little something about computers" just tell them to reformat it.
 
WMI can determine the currently logged on user. Here is a quick script I threw together for ya. It requires admin rights to the PC you are checking.
==========================================================
On Error Resume Next
RunWithCscript

ComputertoCheck = GetInfo("Please provide a computer name that you want to know the currently logged on user." & vbCr & "A . means this computer" ,".")

MsgBox GetCurrentUser(ComputerToCheck)



Function GetCurrentUser(Computer)
On Error Resume Next
Set WMI_Root = GetObject("winmgmts:\\" & Computer & "\Root\Cimv2")
If Err.Number <>0 then
If Err.Number = 462 Then
Wscript.Echo "Computer Not Found Error:" & Err.Number
GetCurrentUser = "Computer Not Found Error:" & Err.Number
Else
Wscript.Echo "Access Denied Error:" & Err.Number
GetCurrentUser = "ACCESS DENIED Error:" & Err.Number
End If
Exit Function
End If

strQuery = "SELECT * FROM Win32_ComputerSystem"

Set UserSet = WMI_Root.ExecQuery(StrQuery)

For Each User In UserSet
If User.UserName <> "" Then
GetCurrentUser=User.UserName
Exit Function
Else
GetCurrentUser="No User is Logged On"
End If
Next
End Function


'This function will return information entered into an inputbox
'It will recall the function if the user enters nothing or clears the default
'It will close the script if the user hits the cancel button
Function GetInfo(ask,default)
getInfo= InputBOx(ask,"MisterNiceGuy Scripting Solutions",default)
emptyAsk="Sorry you must enter something" &vbCr &"Or press Cancel to quit." &vbCr &vbCr
Ask = replace(Ask,EmptyAsk,"")
If getInfo = vbEmpty Then WScript.Quit
If getInfo = "" Then getInfo EmptyAsk & Ask,""
End Function



'This subroutine calls this script with cscript.exe then closes wscript
Sub RunWithCscript
If Lcase(Mid(Wscript.Fullname, InstrRev(Wscript.fullname,"\")+1))="cscript.exe" Then
'nothing
else
Set Shell=CreateObject("Wscript.Shell")
Shell.run "Cscript.exe """ & Wscript.ScriptFullName & """"
WScript.Quit 'Quit Wscript
End If
End Sub
============================================================
 
thanks DestinysDream and thankyou very much MrNiceGuy for the script
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top