I want to run an executable from my webpage; I found a code a snipet to do it:
1 Protected Sub btnRunScript_Click(...) Handles btnRunScript.Click
2
3 Dim ShellProcess As New System.Diagnostics.Process
4 ShellProcess.StartInfo.FileName = "c:\temp\EmailSender.exe"
5
6 ShellProcess.StartInfo.UseShellExecute = False
7 ShellProcess.StartInfo.RedirectStandardOutput = True
8 ShellProcess.StartInfo.RedirectStandardInput = True
9 ShellProcess.StartInfo.RedirectStandardError = True
10 ShellProcess.Start()
11 'ShellProcess.WaitForExit()
12 'ShellProcess.Dispose()
I can get it to work when I use Visual Studio's built-in web server, but not when I plug
this code into my real site which uses IIS. IIS allows me to run Windows-made-applications
such as cmd.exe and batch files. I first tried something simple like using cmd & a batch
to echo to a text file - success for both IIS & VS' server (see code snipet 2). But when I
try using cmd/batch to run my EmailSender.exe, VS's web server lets me but IIS does not
(snipet 3).
This seems like a permissions settings that I must just be missing (?).
[I would not do this on the real server!!], but I gave Everyone 'Full Control' Permission on
c:temp\. In IIS, I gave the default Web Site both 'Script and Executes' permission. This
doesn't seem to be it. What else might I have to do to be able to run my executable?
Code Snipet 2 [works for both VS' server and IIS]:
4 ShellProcess.StartInfo.FileName = "C:\WINDOWS\system32\cmd.exe"
5 ShellProcess.StartInfo.Arguments = String.Concat("/c echo foo > c:\temp\bar.txt")
Code Snipet 3 [works only for both VS' server]:
4 ShellProcess.StartInfo.FileName = "C:\WINDOWS\system32\cmd.exe"
5 ShellProcess.StartInfo.Arguments = String.Concat("/c c:\temp\EmailSender.exe")