473,471 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

call exe from asp.net

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?
Feb 24 '06 #1
4 3864
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?

Feb 24 '06 #2
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?

Feb 24 '06 #3
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

"CsharpGuy" <Cs*******@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.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?

Feb 26 '06 #4
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
Mar 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
35
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
5
by: Amaryllis | last post by:
I'm trying to call a CL which is located on our AS400 from a Windows application. I've tried to code it in different ways, but I seem to get the same error every time. Does anyone have any clue...
13
by: mitchellpal | last post by:
i am really having a hard time trying to differentiate the two..........i mean.....anyone got a better idea how each occurs?
13
by: shsingh | last post by:
I have a class A containing some map as data variables. I creat an object of class A on heap by allocatiing memory by using "malloc". This will return me the required memory but the object is not...
3
by: cberthu | last post by:
Hi all, Is it possible to have two connects in the same rexx script to different DB's? I have to get data form on DB (with specifics selects and filter out some values with RExx) and save the...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.