Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a requirement to execute a batch at server side. This batch creates some files in the server. When ever I am running the following code, I am not getting any output of created files and more over command window is not opened in server .

C#
System.Diagnostics.Process myprocess = new System.Diagnostics.Process(); // Declare New Process 
System.Diagnostics.ProcessStartInfo lObjProcInfo = new System.Diagnostics.ProcessStartInfo(); 
 
lObjProcInfo.UseShellExecute = false; 
lObjProcInfo.RedirectStandardOutput = true; 
lObjProcInfo.CreateNoWindow = true; 
 
lObjProcInfo.RedirectStandardInput = true; 
lObjProcInfo.WindowStyle = ProcessWindowStyle.Normal; 
lObjProcInfo.CreateNoWindow = true; 
 
lObjProcInfo.FileName = lStrBatchPath; 
myprocess = System.Diagnostics.Process.Start(lObjProcInfo);


Please help out.


Thanks
Sreenath
Posted
Updated 9-Apr-12 19:03pm
v2

It seems to be a permission issue. The default account under which ASP.NET application runs has very limited permissions due to security reasons and that account probably do not have permission to start a command prompt.

You will either have to assign required rights to that account or start the process using an account which has required permissions. Process.Start()[^] has an overload for that.

I would suggest Google for ASP.NET worker process permissions to know more about it.

Hope this helps!
 
Share this answer
 
Comments
Sreenath GVS 10-Apr-12 2:04am    
Hi, I am running this application on IIS 5 and impersonated with Admin credentials.
Ankur\m/ 10-Apr-12 2:23am    
Can you check the event log if there is anything relevant logged?
Ankur\m/ 10-Apr-12 3:06am    
Also check this link if it helps - http://stackoverflow.com/questions/5884939/running-a-batch-file-from-an-asp-net-page
Sreenath GVS 11-Apr-12 2:56am    
I have all the permisisons required actually. Please find my actual issue posted...
Hi,

I tried to log output of the batch file run. noticed that after running batch file it directly eneterd into myprocess_Exited event with out any myprocess_OutputDataReceived or myprocess_ErrorDataReceived.

It seems when running batch, actually batch is not been executed...but batch is running on server properly on manual execution

any help over here plzz....

System.Diagnostics.ProcessStartInfo lObjProcInfo = new System.Diagnostics.ProcessStartInfo();

lObjProcInfo.UseShellExecute = false;
lObjProcInfo.CreateNoWindow = true;

lObjProcInfo.RedirectStandardOutput = true;
lObjProcInfo.RedirectStandardInput = true;
lObjProcInfo.RedirectStandardError = true;

lObjProcInfo.WindowStyle = ProcessWindowStyle.Normal;

lObjProcInfo.FileName = lStrBatchPath;

System.Diagnostics.Process myprocess = new System.Diagnostics.Process(); // Declare New Process

myprocess.EnableRaisingEvents = true;

myprocess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(myprocess_OutputDataReceived);
myprocess.ErrorDataReceived += new DataReceivedEventHandler(myprocess_ErrorDataReceived);
myprocess.Exited += new EventHandler(myprocess_Exited);

myprocess.StartInfo = lObjProcInfo;

myprocess.Start();

myprocess.BeginOutputReadLine();
myprocess.BeginErrorReadLine();

myprocess.WaitForExit();



C#
-------------------------------------

public void myprocess_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            try
            {
                clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.INFORMATION, e.Data);

            }
            catch (Exception ex)
            {
                clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, ex.Message.ToString());
            }
        }



        public void myprocess_Exited(object sender, EventArgs e)
        {
            try
            {

                clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.INFORMATION, "Exited (Event) - Batch execution completed");

            }
            catch (Exception ex)
            {
                clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, ex.Message.ToString());
            }
        }



        public void myprocess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            try
            {
                clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, e.Data);

            }
            catch (Exception ex)
            {
                clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, ex.Message.ToString());
            }

        }
 
Share this answer
 
v2
Comments
Ankur\m/ 11-Apr-12 3:00am    
Edit your question by selecting 'Improve Question' link rather than adding an answer.
And please delete the answer after you do so.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900