locked
How can I open an EXE application from a hyperlink control through IE11 browser? RRS feed

  • Question

  • User126014556 posted

    I have an MSSQL database table with the following information:

    Apps
    <a href="file:///C:/Windows/notepad.exe">Notepad</a>
    <a href="%ProgramFiles%\\ABC Software\\bin\\BlueMarble.exe">ABC</a>

    From the ASP.net page:

            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="WebLinkDS" ShowHeader="False" DataKeyNames="App_Code" GridLines="None">
                <Columns>
                    <asp:TemplateField HeaderText="Apps" SortExpression="Apps">
                        <ItemTemplate>
                            <asp:HyperLink ID="hlApps" runat="server" NavigateUrl='<%# Eval("Apps") %>' Text='<%# Eval("Apps") %>' Target="_blank" Visible="true"></asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

    The code page I am using Visual Basic language and I tried the following function:

    Imports System.Diagnostics
    
    Public Class _default
        Inherits System.Web.UI.Page    
    
    Protected Sub GridView2_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView2.RowDataBound
    
            Try
    
                If e.Row.RowType = DataControlRowType.DataRow Then
    
                    Dim hLPath As LinkButton = TryCast(e.Row.FindControl("hlApps"), LinkButton)
                    Dim lblApp As Label = TryCast(e.Row.FindControl("lblAppName"), Label)
                    Dim lblGrp As Label = TryCast(e.Row.FindControl("lblGroup"), Label)
                    Dim lblCod As Label = TryCast(e.Row.FindControl("lblCode"), Label)
                    Dim p As Process = New Process()
    
                    If IsInGroup(lblGrp.Text.Trim()) Then
                        If IsDuplicate(lblCod.Text) Then
    
                            e.Row.Visible = False
                        Else
                            e.Row.Visible = True
                            p.StartInfo.FileName = hLPath.Text.Trim() '-----> Cant get the linkbutton to execute on click 
                            p.Start()
    
                        End If
    
                    Else
                        e.Row.Visible = False
    
                    End If
    
                End If
    
            Catch ex As Exception
    
            End Try
    
        End Sub
    
        Public Function IsInGroup(ByVal GroupName As String) As Boolean
    
            Dim MyIdentity As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
            Dim MyPrincipal As System.Security.Principal.WindowsPrincipal = New System.Security.Principal.WindowsPrincipal(MyIdentity)
            Return MyPrincipal.IsInRole(GroupName)
    
        End Function
    
        Private Function IsDuplicate(ByVal appName As String) As Boolean
            Dim result As Boolean
            result = (From x In appNames Where x = appName
                      Select x).Any()
            If Not result Then
                appNames.Add(appName)
            End If
            Return result
        End Function
    
    End Class

    I appreciate any help and thanks in advance.

    Tuesday, April 24, 2018 6:06 AM

Answers

  • User475983607 posted

    It seems like it works using an click event because your development machine is both the client and server.  Once deployed to a server the code will no longer work as the code will try to open notepad on the server,

    It is not possible to open local resource with a link due to browser security.  Browser do not allow a remote web server to access files on the client machine.  If this security measure was not in place web server could grab whatever file they wish from user machines. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 24, 2018 10:48 AM

All replies

  • User475983607 posted

    It is not possible to open a local resource with a link due to browser security.

    Tuesday, April 24, 2018 10:19 AM
  • User126014556 posted

    I am able with the button event on click.

    Is it not possible with the linkbutton in the GridView RowDataBound?

        Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim p As Process = New Process()
            p.StartInfo.FileName = "notepad.exe"
            p.Start()
    
        End Sub

    Tuesday, April 24, 2018 10:36 AM
  • User475983607 posted

    It seems like it works using an click event because your development machine is both the client and server.  Once deployed to a server the code will no longer work as the code will try to open notepad on the server,

    It is not possible to open local resource with a link due to browser security.  Browser do not allow a remote web server to access files on the client machine.  If this security measure was not in place web server could grab whatever file they wish from user machines. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 24, 2018 10:48 AM
  • User126014556 posted

    Good point.

    Probably no solution at this point.

    Tuesday, April 24, 2018 10:54 AM