Webpage to see if someone is logged into PC's via RDP

Discussion in 'ASP General' started by John Whitmer, Mar 15, 2005.

  1. John Whitmer

    John Whitmer Guest

    I am trying to put together a web page to show remote users which PC's are
    available for RDP so they can use. The page work's fine except for when the
    goes to the pc to pull the info on if anybody is logged in or not it seems
    to have trouble. here is the blurb from the temp file that gets created on
    the webserver.
    "Error opening Terminal server Computer-01 Error [5]:Access is denied."
    The webserver Anon account is using a Domain account that has full rights on
    those boxes. Below is my webpage.





    <HTML>
    <HEAD>
    <TITLE>Blade Availability.&nbsp; Please be Patient!</TITLE>
    <SCRIPT LANGUAGE="VBScript" runat="server">
    Response.Buffer=True
    Response.Expires=-1
    Server.ScriptTimeout= 600


    On Error Resume Next

    ' This script will pull computers from a text file and give you feedback if
    someone is logged in via local or RDP.

    Dim fso, f, inputFile, strCompName, strUserName

    'Text file has a list of PC's I want this script to run against
    inputFile = "\\Servername\text\computers.txt"

    set fso = CreateObject("Scripting.FileSystemObject")
    set f = fso_OpenTextFile(inputFile)

    Do While f.AtEndOfLine <> True
    strCompName = Trim(f.ReadLine)
    If strCompName <> "" Then

    strCompName = UCase(strCompName)
    strUserName = GetUser(strCompName)

    If IsEmpty(strUserName) Then
    Response.Write strCompName & " ; Could not connect to computer " &
    "<br>"
    Response.Flush()
    ElseIf strUserName = "" Then
    Response.Write strCompName & " ; No user is logged on " & "<a
    href=""rdp.asp?hostname="&wks(r) &""">CLICK here to connect</a><br>"
    Response.Flush()
    Else
    Response.Write strCompName & " ; Logged on user name: " &
    strUserName & "<a href=""rdp.asp?hostname="&wks(r) &""">CLICK here to
    connect</a><br>"
    Response.Flush()
    End If
    End If
    Loop

    f.close

    wscript.echo "end of file"


    Function GetUser(sHost)
    ' Function will return logged in user name from QWINSTA.EXE
    ' regardless of it is a console or RDP user
    ' Windows XP only
    '
    ' Return values:
    ' If input to function (host name) is empty, returns Empty
    ' If QWINSTA.EXE cannot connect to host, returns Empty
    ' If no user is listed by QWINSTA.EXE, returns ""
    ' If user is listed, returns user name

    If sHost = "" Then
    Exit Function '-----> return Empty
    End if

    Set oShell = CreateObject("Wscript.Shell")
    Set oFS = CreateObject("Scripting.FileSystemObject")

    sTmpFile = oFS.GetSpecialFolder(2).ShortPath & "\" & oFS.GetTempName

    response.write(sTmpFile)

    'Run command and redirect stdout and stderr into temp file
    oShell.Run "%ComSpec% /c %SystemRoot%\System32\QWINSTA.EXE /SERVER:" _
    & sHost & " >" & sTmpFile & " 2>&1", 0, True

    On Error Resume Next
    'Open the temp file
    Set oTF = oFS.OpenTextFile(sTmpFile)

    'Parse the file

    ' Read first line
    sLine = oTF.ReadLine
    If Err.Number <> 0 Then
    ' Something is wrong.
    Exit Function '-----> return Empty
    End If
    On Error Goto 0

    If Left(Trim(sLine), 26) <> "SESSIONNAME USERNAME" Then
    ' Something is wrong. Most likely is the content of the first line
    ' this: "Error opening Terminal server <host name>"
    Exit Function '-----> return Empty
    End If

    ' Read second line
    sLine = oTF.ReadLine
    'Close file
    oTF.Close
    'Delete it
    oFS.DeleteFile sTmpFile

    sChoppedLine = Mid(sLine, 20)
    If Left(sChoppedLine, 1) = " " Then
    ' no user found
    GetUser = ""
    Else
    ' get the user name
    GetUser = Split(sChoppedLine)(0)
    End If

    End Function


    </SCRIPT>
    </BODY>
    <body bgcolor="#EBF2FC">

    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p align="center"><font size="5">Remote Desktop Connections</font></p>
    </HTML>




    </SCRIPT>
    </BODY>
    </HTML>
     
    John Whitmer, Mar 15, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keithb
    Replies:
    0
    Views:
    652
    keithb
    Feb 16, 2006
  2. Mike Wahler

    RDP or ICA?

    Mike Wahler, Jul 31, 2003, in forum: C++
    Replies:
    2
    Views:
    537
    Rob Williscroft
    Aug 2, 2003
  3. Chris Lasher
    Replies:
    1
    Views:
    337
    Alan Kennedy
    Dec 3, 2004
  4. Replies:
    0
    Views:
    887
  5. Replies:
    1
    Views:
    966
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Apr 12, 2007
Loading...

Share This Page