Re: System.Diagnostics.Process not working !! please help




You must be having permissions problem. You need to give approriate
permissions to the directory that you are trying to access on the harddrive
from the virtual directory. You can right click the directory where your
batch file is and goto the "security" tab, add the ASPNET user in it and
give appropriate permissions. Although this would be insecure i beleive but
first try this.

I created a new web appplication to do this in visual studio 2k5, but have
no problems running this code. What exact error do u get when you run this
code?

Ab.

"Nurit N" <NuritN@xxxxxxxxxxxx> wrote in message
news:uYGWt0eEGHA.1088@xxxxxxxxxxxxxxxxxxxxxxx
> Thanks for your replay.
>
> I tried the code you sent me and it's working for me as well.
>
> The different (and I'm sorry not to mentioned that before) that I'm
running
> on a web service application.
>
> My program supposes to start the CMD on the server.
>
> Any Idea?
>
>
> "Abubakar" <abubakarm@xxxxxxxxx> wrote in message
> news:uEfYHCeEGHA.1384@xxxxxxxxxxxxxxxxxxxxxxx
> > Hi,
> > I just tried your code and it works fine ( with a lil modification) for
> > me,
> > the strOutput gets the right output. I'm pasting the code here and you
> > check
> > it works for you or not. Make a new console application and past the
code
> > there:
> >
> > //--------------<code>
> > using System;
> >
> > using System.Diagnostics;
> > using System.ComponentModel;
> >
> > namespace ConsoleApplication1
> > {
> >
> > class csomething
> > {
> > public static void Main()
> > {
> > csomething c = new csomething();
> > c.dosomething();
> >
> > }
> > public void dosomething()
> > {
> >
> > try
> > {
> > System.Diagnostics.Process MFGProc = new
System.Diagnostics.Process();
> > MFGProc.StartInfo.FileName =
> > AppDomain.CurrentDomain.BaseDirectory+@"bat.bat"; //strMfgWorkDir +
> > strMfgBatFile;
> > MFGProc.StartInfo.WorkingDirectory =
> > AppDomain.CurrentDomain.BaseDirectory;
> > //@"D:\mycode\ConsoleApplication1\ConsoleApplication1\bin";
> > MFGProc.StartInfo.UseShellExecute = false;
> > MFGProc.StartInfo.RedirectStandardError = true;
> > MFGProc.StartInfo.RedirectStandardOutput = true;
> > MFGProc.Start();
> >
> > string strOutput = MFGProc.StandardOutput.ReadToEnd();
> > string strError = MFGProc.StandardError.ReadToEnd();
> > MFGProc.WaitForExit();
> >
> > if (MFGProc.ExitCode == 0)
> > {
> > //Ok = true;
> > Console.Write("no problem");
> >
> > }
> > else
> > {
> > //strErrorMsg = " Running failed. Description: " + strError;
> > Console.Write("some problem");
> > }
> > }
> > catch (Win32Exception e)
> > {
> > Console.Write("W32 Error:" + e.NativeErrorCode.ToString() + "." +
> > e.Message);
> > }
> >
> > catch (Exception err)
> > {
> > // Process other errors here
> > Console.Write("RunMFGCimSession Other error. ErrorMessage: " +
> > err.Message);
> > }
> >
> > }
> >
> > }//class
> >
> > }
> >
> > //--------------</code>
> >
> > make a batch file in your debug bin directory and name it bat.bat and
use
> > notepad to add the "echo hello world" in it.
> >
> > -Abubakar.
> >
> > ++==
> > P.S: when pasting your code for others to run, make sure its complete in
a
> > way that anyone can just copy and past it in the editor and it would
give
> > the output that your writing about. Your code had missing variables and
> > missing using statements. It takes time to change those things and
chances
> > for your getting help reduces. So always submit the complete working
code.
> > Plz read this link http://www.pobox.com/~skeet/csharp/complete.html
> > -Thanks
> >
> > "Nurit N" <NuritN@xxxxxxxxxxxx> wrote in message
> > news:ehIvfsdEGHA.140@xxxxxxxxxxxxxxxxxxxxxxx
> >> This is the third newsgroup that I'm posting my problem.
> >> I'm sorry for the multiple posts but the matter becoming urgent.
> >>
> >> I hope this is the right place for it...
> >>
> >>
> >>
> >> I have created a very simple batch file (echo hello world) and was
trying
> > to
> >> retrieve the standard output but every time I run the code it returns
> >> ExitCode as 1.
> >>
> >> The batch file runs just fine from command line.
> >>
> >> There is no Win32Exception (no ERROR_FILE_NOT_FOUND and no
> >> ERROR_ACCESS_DENIED)
> >>
> >> Also strOutput and strError returns empty.
> >>
> >> What ExitCode1 means?
> >>
> >> Am I missing on something?
> >>
> >> Here is the code:
> >>
> >> try
> >> {
> >> System.Diagnostics.Process MFGProc = new
> >> System.Diagnostics.Process();
> >> MFGProc.StartInfo.FileName = strMfgWorkDir + strMfgBatFile;
> >> MFGProc.StartInfo.WorkingDirectory = strMfgWorkDir;
> >> MFGProc.StartInfo.UseShellExecute = false;
> >> MFGProc.StartInfo.RedirectStandardError = true;
> >> MFGProc.StartInfo.RedirectStandardOutput = true;
> >> MFGProc.Start();
> >>
> >> string strOutput = MFGProc.StandardOutput.ReadToEnd();
> >> string strError = MFGProc.StandardError.ReadToEnd();
> >> MFGProc.WaitForExit();
> >>
> >> if (MFGProc.ExitCode == 0)
> >> {
> >> Ok = true;
> >> }
> >> else
> >> {
> >> strErrorMsg = " Running failed. Description: " + strError;
> >> }
> >> }
> >> catch (Win32Exception e)
> >> {
> >> strErrorMsg = "W32 Error:" + e.NativeErrorCode.ToString() + "." +
> >> e.Message ;
> >> }
> >>
> >> catch (Exception err)
> >> {
> >> // Process other errors here
> >> strErrorMsg = ("RunMFGCimSession Other error. ErrorMessage: " +
> >> err.Message );
> >> }
> >>
> >> Thanks
> >>
> >> Nurit
> >>
> >>
> >>
> >>
> >
> >
>
>


.



Relevant Pages

  • .NET Deployment: Minimum Customer Effort
    ... J# Browser Controls. ... Configuration tool and giving the required permission level based on ... I've started to look at writing a batch file that uses Caspol.exe to ... agree to the permissions demanded by our code? ...
    (microsoft.public.dotnet.security)
  • Re: Cannot Execute Batch File
    ... I have given full permissions for the shortcut. ... The error says that I do not have permissions to execute this file. ... We have newly installed a Terminal Server. ... with a Batch file, that is shared on a different Server. ...
    (microsoft.public.windows.terminal_services)
  • Re: Install of Management Studio fails with SMS
    ... If you have not already tried you could ask in the SMS newsgroups. ... >> should work through sms...if it is a permissions issue, ... >> Also I have tried putting this command in a batch file which SMS doesn't ... >>> John ...
    (microsoft.public.sqlserver.setup)
  • Re: Login Script Trouble
    ... I figured this one out with regards to why the batch file didn't ... inherit the permissions from the scripts folder. ...
    (microsoft.public.windows.server.general)
  • [Fwd: apache 1.3.x]
    ... has somebody a solution for the 'missing permissions'?? ... configured -- resuming normal operations ... access to /nwsbrief_19.doc failed because search permissions are ...
    (Debian-User)