How to execute a DOS command from an ASP.NET application deployed on the remote network server?
Posted on 2004-11-01
I have to map a samba share on a remote server from an ASP.NET application using the NET USE command. I was able to do it if the ASP.NET application was created, compiled, and located on my local server. But after I move it to the network server, the NET USE returns "Access Denied". To simplify the analysis, I am trying to execute a simple copy command instead, but still, it works on the local server, but does not work on the remote one.
I probably either have permissions problem or miss something doing the deployment.
I use the following C# code:
// some code . . . . . . . .
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.UseShellExecute = false;
/* the CopyFile.bat contains just one statement:
copy c:\devel\uploads\test1.txt C:\devel\test\test1.txt
//// other code…
// . . . . . . . . . . . . . . . . . . . . . . . .
catch (Exception exc)
// The code to display the exc.Message
//. . . . . . . . . . . .
Again, when I try this code on a local server, a file is being copied.
After I move the application to the remote server, exception “Access Denied” is being thrown.
I tried to add the ASPNET account on the remote server to the Administrators group. It did not work.
On the local server it works OK without adding the ASPNET account to the Administrators group.
To deploy, I just copied the application’s files to the appropriate remote server’s IIS directory.
The page is displayed OK, and only the attempt to execute a command fails.
If I execute the CopyFile.bat from the Windows START/Run box, it works OK on both local and network server, therefore the copy command is OK.
Any suggestions will be much appreciated.