Running a program from ASP.net

zeocrash

Newcomer
Joined
Sep 15, 2004
Messages
8
Ok, I'm writing a user database for my company's intranet.
The database uses an sql file to store user details. These details are displayed in a data grid.
At the end of the datagrid, there is a button that allows the administrator to vnc onto a user's computer.
Now when i run the application through visual studio, it works fine.

When the application is run through iis, over the intranet though. nothing happens when the button is clicked.

Code:
    Protected Sub usergrid_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles usergrid.RowCommand
        ' If multiple ButtonField column fields are used, use the
        ' CommandName property to determine which button was clicked.
        If Not Session("doneonce") Then 'stops the code running twice
            If e.CommandName = "vncuser" Then 'if the button is pressed

                ' Convert the row index stored in the CommandArgument
                ' property to an Integer.
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)

                ' Get the last name of the selected author from the appropriate
                ' cell in the GridView control.
                Dim selectedRow As GridViewRow = usergrid.Rows(index)
                Dim contactCell As TableCell = selectedRow.Cells(6)
                Dim contact As String = contactCell.Text
                If Session("superuser") = True Then


                    vnc_connect(contact)
                Else
                    authtxt.Text = "<font color=red>You are not authorised to use VNC</font>"
                End If
                ' Display the selected author.
                'Message.Text = "You selected " & contact & "."

            End If
        End If
        If Session("doneonce") = True Then
            Session("doneonce") = False
        Else
            Session("doneonce") = True
        End If
    End Sub
    Private Sub vnc_connect(ByVal ip As String)
        Dim vncfile As String
        'vnc file contents
        vncfile = "[Connection]" & vbCrLf & "Host=" & ip & vbCrLf & "Password=password" & vbCrLf & "[Options]" & vbCrLf & "UseLocalCursor=1" & vbCrLf & "UseDesktopResize=1" & vbCrLf & "FullScreen=0" & vbCrLf & "FullColour=1" & vbCrLf & "LowColourLevel=1" & vbCrLf & "PreferredEncoding=hextile" & vbCrLf & "AutoSelect=1" & vbCrLf & "Shared=0" & vbCrLf & "SendPtrEvents=1" & vbCrLf & "SendKeyEvents=1" & vbCrLf & "SendCutText=1" & vbCrLf & "AcceptCutText=1" & vbCrLf & "DisableWinKeys=1" & vbCrLf & "Emulate3=0" & vbCrLf & "PointerEventInterval=0" & vbCrLf & "Monitor=\\.\DISPLAY1" & vbCrLf & "MenuKey=F8" & vbCrLf & "AutoReconnect=1"
        Try
            Kill("C:\Program Files\RealVNC\VNC4\user.vnc") 'delete old vnc file
        Catch ex As Exception

        End Try
        'create new vnc file
        My.Computer.FileSystem.WriteAllText("C:\Program Files\RealVNC\VNC4\user.vnc", vncfile, False, Encoding.ASCII) 'must be ascii encoded otherwise hidden characters are inserted at the begining of the file
        'run vnc with vnc file
        Shell(ChrW(34) & "C:\Program Files\RealVNC\VNC4\vncviewer.exe " & ChrW(34) & "-config " & ChrW(34) & "c:\program files\realvnc\vnc4\user.vnc", AppWinStyle.NormalFocus, False, -1) ' & ChrW(34) & is ascii code for quote. must be added for command line to work

    End Sub

I think it may be due to my inappropriate use of the shell command. any ideas??
 
The shell command will run the application on the IIS box itself (as whatever user the web-server is configured to run as).

Rather than trying to launch the .vnc file on the server you could have it downloaded to the client and run from there - that should launch the vnc viewer on the destop.
 
so how would i go about loading the vnc file onto the client system and running vnc viewer client side??
 
Something like
Visual Basic:
Dim vncfile As String

'vnc file contents
vncfile = "[Connection]" & vbCrLf & "Host=" & ip & vbCrLf & "Password=password" & vbCrLf & "[Options]" & vbCrLf & "UseLocalCursor=1" & vbCrLf & "UseDesktopResize=1" & vbCrLf & "FullScreen=0" & vbCrLf & "FullColour=1" & vbCrLf & "LowColourLevel=1" & vbCrLf & "PreferredEncoding=hextile" & vbCrLf & "AutoSelect=1" & vbCrLf & "Shared=0" & vbCrLf & "SendPtrEvents=1" & vbCrLf & "SendKeyEvents=1" & vbCrLf & "SendCutText=1" & vbCrLf & "AcceptCutText=1" & vbCrLf & "DisableWinKeys=1" & vbCrLf & "Emulate3=0" & vbCrLf & "PointerEventInterval=0" & vbCrLf & "Monitor=\\.\DISPLAY1" & vbCrLf & "MenuKey=F8" & vbCrLf & "AutoReconnect=1"

Response.Clear()
Response.ClearHeaders()
Response.ContentType = "application/text"
Response.AppendHeader("Content-Disposition", "attachment; filename=Run.vnc")
Dim b() As Byte = System.Text.ASCIIEncoding.ASCII.GetBytes(vncfile)
Response.BinaryWrite(b)

Response.End()
on the server side should generate the relevant content and send it down to the browsers as a .vnc file - as long as the client has the vnc viewer installed it should prompt them to open it with the correct app and that should be that.

You may need to change the line
Visual Basic:
Response.ContentType = "application/text"
to
Visual Basic:
Response.ContentType = "VncViewer/Config"
though - I don't have vnc installed here so I couldn't test it for sure.
 
Back
Top