Help with Process function - ASP page using C#

V

vbMark

Here is my C# code in the ASP.NET page.

public static void DoConvert ( string sFile )
{
string cmd = "foo.exe" ;
string param = " /bar.txt" ;
Process myproc ; // <-- Error here
ProcessStartInfo startInfo = new ProcessStartInfo ( cmd , param ) ;
startInfo.CreateNoWindow = true ;
startInfo.WindowStyle = ProcessWindowStyle.Hidden ;
myproc = Process.Start ( startInfo );
//myproc.WaitForExit () ;
myproc.Close() ;
}

When I run it I get:
Compiler Error Message: CS0246: The type or namespace name 'Process'
could not be found (are you missing a using directive or an assembly
reference?)

I think this is because I need:

using System.ComponentModel;

But I can't figure out where to put it. I've tried several places but
still got the error. Any ideas?

Thanks!
 
N

Nicholas Paldino [.NET/C# MVP]

vbMark,

You need to add a directive to use the System.Diagnostics namespace in
your page. You can also use the full name of the process and start info
classes, like this:

System.Diagnostics.Process myproc ; // <-- Error here
System.Diagnostics.ProcessStartInfo startInfo = new
System.Diagnostics.ProcessStartInfo ( cmd , param ) ;
startInfo.CreateNoWindow = true ;
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden ;
myproc = System.Diagnostics.Process.Start ( startInfo );

Hope this helps.
 
V

vbMark

vbMark,

You need to add a directive to use the System.Diagnostics
namespace in
your page. You can also use the full name of the process and start
info classes, like this:

System.Diagnostics.Process myproc ; // <-- Error here
System.Diagnostics.ProcessStartInfo startInfo = new
System.Diagnostics.ProcessStartInfo ( cmd , param ) ;
startInfo.CreateNoWindow = true ;
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden ;
myproc = System.Diagnostics.Process.Start ( startInfo );

Hope this helps.


Well now I'm getting a different error:

Error saving file: System.ComponentModel.Win32Exception: Access is denied
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
startInfo) at System.Diagnostics.Process.Start() at
System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at
converter.WebForm1.DoConvert(String sFile) in c:\inetpub\wwwroot
\converter\default.aspx.cs:line 39 at ASP.default_aspx.Button1_Click
(Object Source, EventArgs e) in
http://localhost/converter/default.aspx:line 34

Is this because it can't run an executable or some other reason? Is this
how one is supposed to run an executable at the server?
 
N

Nicholas Paldino [.NET/C# MVP]

vbMark,

This is the result of not having sufficient rights. By default, ASP.NET
runs under the ASPNET local account, which has a limited set of rights. If
anything, you need to impersonate a user that has the rights that your
executable needs to operate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top