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
============================================================