Home All Groups Group Topic Archive Search About
Author
24 Feb 2006 8:09 PM
CsharpGuy
I need to call an exe that resides on a server on the network from a ASP.NET
page.
first, is this possible, and if so who would I go about doing it? What is
need to do this and have the exe run when its called?

Author
24 Feb 2006 8:17 PM
Peter Bromberg [C# MVP]
CsharpGuy,
Take a look at the System.Diagnostics.Process class.
The documentation is pretty good, and it is relatively easy to use.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Show quoteHide quote
"CsharpGuy" wrote:

> I need to call an exe that resides on a server on the network from a ASP.NET
> page.
> first, is this possible, and if so who would I go about doing it? What is
> need to do this and have the exe run when its called?
Are all your drivers up to date? click for free checkup

Author
24 Feb 2006 8:36 PM
CsharpGuy
though this EXE is a program not a process, does that make a difference or no?


Show quoteHide quote
"Peter Bromberg [C# MVP]" wrote:

> CsharpGuy,
> Take a look at the System.Diagnostics.Process class.
> The documentation is pretty good, and it is relatively easy to use.
> Peter
>
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "CsharpGuy" wrote:
>
> > I need to call an exe that resides on a server on the network from a ASP.NET
> > page.
> > first, is this possible, and if so who would I go about doing it? What is
> > need to do this and have the exe run when its called?
Author
26 Feb 2006 8:41 AM
Eliyahu Goldin
No.

But you will have to take care of security issues, especially if the exe
resides on the network. ASP.NET usually runs under a low-privileged user
account.

Eliyahu

Show quoteHide quote
"CsharpGuy" <Csharp***@discussions.microsoft.com> wrote in message
news:BB3D99EC-C2EC-4194-B1F6-F20A6D25CB4C@microsoft.com...
> though this EXE is a program not a process, does that make a difference or
> no?
>
>
> "Peter Bromberg [C# MVP]" wrote:
>
>> CsharpGuy,
>> Take a look at the System.Diagnostics.Process class.
>> The documentation is pretty good, and it is relatively easy to use.
>> Peter
>>
>> --
>> Co-founder, Eggheadcafe.com developer portal:
>> http://www.eggheadcafe.com
>> UnBlog:
>> http://petesbloggerama.blogspot.com
>>
>>
>>
>>
>> "CsharpGuy" wrote:
>>
>> > I need to call an exe that resides on a server on the network from a
>> > ASP.NET
>> > page.
>> > first, is this possible, and if so who would I go about doing it? What
>> > is
>> > need to do this and have the exe run when its called?
Author
10 Mar 2006 8:13 PM
Tim Curtin MSMVP
Here's some code:
it launches an exe, redirects the input to a stream object. the exe creates a text file. I read it in, parse it then display the output on the page:

Imports System.IO
Imports System.Diagnostics

Dim PROCESS_SPCS83 As Process
        Dim northingInput, eastingInput As Decimal
        northingInput = Me.txtNorthing.Text '818667  'values hard-coded for testing
        eastingInput = Me.txtEasting.Text   '1061050
        Dim StationName As String = "CC15-44"
        Dim n2, e2 As String
        Dim logonUser As UserLogon
        Try
            'Coordinate Input information
            'convert string to 3 decimal places as app requires it
            n2 = northingInput.ToString("n3").Replace(",", "")
            e2 = eastingInput.ToString("n3").Replace(",", "")

            'dynamic file name (it dosen't write out the extension for some reason)
            Dim sOutputFile As String = Server.MapPath(Environment.TickCount.ToString)

            'args for input (StandardInput would be Keyboard)
            Dim arArgs(10) As String
            arArgs(0) = "2"
            arArgs(1) = "Y"
            arArgs(2) = "Y"
            arArgs(3) = sOutputFile
            arArgs(4) = "N"
            arArgs(5) = StationName
            arArgs(6) = n2
            arArgs(7) = e2
            arArgs(8) = "0600"
            arArgs(9) = "N"
            arArgs(10) = "N"

            Dim i As Integer
            logonUser = New UserLogon
            logonUser.Logon("tcurtin", "kevalyeri", "")
            'stream for redirecting input
            Dim ArgStream As StreamWriter

            PROCESS_SPCS83 = New Process

            With PROCESS_SPCS83

                With .StartInfo()
                    .FileName = Server.MapPath("SPCS83.EXE")
                    .RedirectStandardInput = True  'use streamwriter instread
                    .UseShellExecute = False
                    .WindowStyle = ProcessWindowStyle.Hidden
                End With

                .Start()
                'redirect standard input from keyboard to stream
                ArgStream = .StandardInput

                'loop through array feeding input args (command line)
                Dim bytCount As Byte = arArgs.GetLength(0) - 1
                With ArgStream
                    For i = 0 To bytCount
                        .WriteLine(arArgs(i)) 'pass command line input args
                    Next
                End With

                'application normally exits after last arg, but check anyway
                .WaitForExit()
            End With

            'assume exe has written out the file.
            If File.Exists(sOutputFile) Then
                Dim fs As FileStream = File.Open(sOutputFile, FileMode.Open)
                Dim arBytes(), ascII() As Byte

                ReDim arBytes(fs.Length)
                Dim intBytesRead As Long = fs.Read(arBytes, 0, arBytes.Length)
                fs.Close()
                File.Delete(sOutputFile)
                'convert byte array to string and re-split into array, split at carriage returns
                Dim sArgs As String = System.Text.ASCIIEncoding.ASCII.GetString(arBytes)
                Dim sLines() As String = sArgs.Split(vbCrLf)
                For i = 0 To sLines.Length - 1
                    If sLines(i).IndexOf(StationName) > 0 Then
                        'read in the line and parse into array
                        Dim arPointLine() As String = sLines(i).Split(" ")
                        Dim northing As String = arPointLine(31) & Chr(176) & " " & arPointLine(32) & Chr(39) & " " & arPointLine(33) & Chr(34)
                        Dim easting As String = arPointLine(34) & Chr(176) & " " & arPointLine(35) & Chr(39) & " " & arPointLine(36) & Chr(34)
                        Me.lblLongitude.Text = northing
                        Me.lblLatitude.Text = easting
                        Exit For
                    End If
                Next
            Else
                Me.lblMessage.Text = "File: " & sOutputFile & " Not found"
            End If

        Catch ex As Exception
            Me.lblMessage.Text = ex.Message
        Finally
            If PROCESS_SPCS83 Is Nothing Then
                With PROCESS_SPCS83
                    If Not .HasExited Then
                        .Kill()
                        PROCESS_SPCS83 = Nothing
                    End If
                End With
            End If

            logonUser.LogOff()
        End Try
    End Sub
---
Posted via www.DotNetSlackers.com



Post Thread options