Quantcast
Channel: Remote Desktop Services (Terminal Services) forum
Viewing all articles
Browse latest Browse all 1106

VBscript to determine %clientname%

$
0
0

I have a vbscript that runs when a user logs onto our terminal servers, which writes the username and time logged on / logged off to a text file.

I am wanting to also capture the %clientname% (the name of the PC that the remote user is working on to connect to the TS) to this text file.

Any idea how this can be done with my existing script?

On Error Resume Next

strComputer = "."
Const ForAppending = 8
Set oNetwork = wscript.CreateObject("wscript.network") 'Create network object
Set objShell = Wscript.CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
strUserName    = oNetwork.userName
strComputerName    = oNetwork.computerName
strOnline = "Offline"

    For Each objAdapter in colAdapters
        If Not IsNull(objAdapter.IPAddress) Then
            For i = LBound(objAdapter.IPAddress) To UBound(objAdapter.IPAddress)
                If not objAdapter.IPAddress(i) = "0.0.0.0" Then
                    strOnline = "Online"
                End If
            Next
        End If
    Next

    Set objTextFile = objFSO.OpenTextFile ("c:\windows\system32\logfiles\logonevents.txt", ForAppending, True)
    objTextFile.WriteLine("Logoff" & vbTab & strComputerName & vbTab & struserName & vbTab & Now() & vbTab & strOnline)
    objTextFile.Close

Thanks in advance!


Viewing all articles
Browse latest Browse all 1106

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>