Process Problems - XCOPY ExitCode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Grigs

    Process Problems - XCOPY ExitCode

    Hello,

    I am attempting to write a Web Method in my Web Service that starts a
    process that runs the XCOPY command with passed in parameters. It is failing
    on me through code. However, if I take the exact same string it is passing
    and past it into a Command prompt, it works perfectly. That told me it may
    be a permissions/impersonation issue. I am now running it as a special
    ServiceAccount I have created that is a Domain Admin. It still does not
    work. I then looked to see if it was returning an error or ExitCode and it
    is.

    The ExitCode == 4 which for XCOPY means "Initializa tion error occurred.
    There is not enough memory or disk space, or you entered an invalid drive
    name or invalid syntax on the command line."

    Here is my code and the output follows - Can anyone help me here? Do I
    really need impersonation or is it some other fix?

    FYI: The AddSQLStatement method is simply a way I store information in a
    string array for extraction later to determine what happens in my code.


    string sXCopy = "\"" + sBaseFolder + sSourceFolder + "\"" +
    " \"" + sBaseFolder + sDestination + "\"" +
    " /E /V /C /I /O /Y /K";

    AddSQLStatement ("XCOPY: " + sXCopy);
    AddSQLStatement ("USER: " + System.Environm ent.UserDomainN ame + "\\" +
    System.Environm ent.UserName);
    AddSQLStatement ("User: " +
    System.Security .Principal.Wind owsIdentity.Get Current().Name) ;

    try {
    Process oProc = new Process();
    oProc.EnableRai singEvents = false;
    oProc.StartInfo .FileName = "XCOPY";
    oProc.StartInfo .Arguments = sXCopy;
    oProc.StartInfo .RedirectStanda rdOutput = true;
    oProc.StartInfo .UseShellExecut e = false;
    oProc.Start();
    AddSQLStatement ("StdOut: " + oProc.StandardO utput.ReadToEnd ()); ////
    oProc.WaitForEx it();
    AddSQLStatement ("Exit Code: " + oProc.ExitCode. ToString()); ////
    } catch(Exception e) {
    AddSQLStatement ("XCOPY Error: " + e.ToString());
    exLastError = e;
    } // try-catch

    <<<<<< This is the output >>>>>>>>

    Exit Code: 4
    StdOut: 0 File(s) copied
    User: CSDomain\Servic eAccount
    USER: CSDOMAIN\Servic eAccount
    XCOPY: "\\Cochise\JobF olders\_FolderT emplate"
    "\\Cochise\JobF olders\6126_Tes t25e" /E /V /C /I /O /Y /K

    --
    Thanx,
    Grigs
  • Brian Cryer

    #2
    Re: Process Problems - XCOPY ExitCode

    "Grigs" <Grigs@discussi ons.microsoft.c om> wrote in message
    news:D1E3899B-E228-40F7-BA36-2069923FBCC0@mi crosoft.com...[color=blue]
    > Hello,
    >
    > I am attempting to write a Web Method in my Web Service that starts a
    > process that runs the XCOPY command with passed in parameters. It is
    > failing
    > on me through code. However, if I take the exact same string it is
    > passing
    > and past it into a Command prompt, it works perfectly. That told me it
    > may
    > be a permissions/impersonation issue. I am now running it as a special
    > ServiceAccount I have created that is a Domain Admin. It still does not
    > work. I then looked to see if it was returning an error or ExitCode and
    > it
    > is.
    >
    > The ExitCode == 4 which for XCOPY means "Initializa tion error occurred.
    > There is not enough memory or disk space, or you entered an invalid drive
    > name or invalid syntax on the command line."
    >
    > Here is my code and the output follows - Can anyone help me here? Do I
    > really need impersonation or is it some other fix?
    >
    > FYI: The AddSQLStatement method is simply a way I store information in a
    > string array for extraction later to determine what happens in my code.
    >
    >
    > string sXCopy = "\"" + sBaseFolder + sSourceFolder + "\"" +
    > " \"" + sBaseFolder + sDestination + "\"" +
    > " /E /V /C /I /O /Y /K";
    >
    > AddSQLStatement ("XCOPY: " + sXCopy);
    > AddSQLStatement ("USER: " + System.Environm ent.UserDomainN ame + "\\" +
    > System.Environm ent.UserName);
    > AddSQLStatement ("User: " +
    > System.Security .Principal.Wind owsIdentity.Get Current().Name) ;
    >
    > try {
    > Process oProc = new Process();
    > oProc.EnableRai singEvents = false;
    > oProc.StartInfo .FileName = "XCOPY";
    > oProc.StartInfo .Arguments = sXCopy;
    > oProc.StartInfo .RedirectStanda rdOutput = true;
    > oProc.StartInfo .UseShellExecut e = false;
    > oProc.Start();
    > AddSQLStatement ("StdOut: " + oProc.StandardO utput.ReadToEnd ()); ////
    > oProc.WaitForEx it();
    > AddSQLStatement ("Exit Code: " + oProc.ExitCode. ToString()); ////
    > } catch(Exception e) {
    > AddSQLStatement ("XCOPY Error: " + e.ToString());
    > exLastError = e;
    > } // try-catch
    >
    > <<<<<< This is the output >>>>>>>>
    >
    > Exit Code: 4
    > StdOut: 0 File(s) copied
    > User: CSDomain\Servic eAccount
    > USER: CSDOMAIN\Servic eAccount
    > XCOPY: "\\Cochise\JobF olders\_FolderT emplate"
    > "\\Cochise\JobF olders\6126_Tes t25e" /E /V /C /I /O /Y /K
    >
    > --
    > Thanx,
    > Grigs[/color]

    I may be barking up the wrong tree here, but what is the working directory
    when you launch xcopy? I seem to recall that dos commands don't take kindly
    to be kicked off on a share and like the current working directory to be
    something with a drive letter.

    Just a thought.

    Brian.

    Brian Cryer's home page, a collection of notes on my professional and personal interests. Including C#, VB.Net, Windows, DB admin, Delphi and more.



    Comment

    • Grigs

      #3
      Re: Process Problems - XCOPY ExitCode

      Brian,

      Thanks. I tried your suggestion with no luck. I put in C:\ with no luck.
      I even put the exact path to the XCOPY function. I even tested changing the
      UNC paths to be a drive letter and that didn't work either.

      Anyone have any other suggestions?

      --
      Thanx,
      Grigs


      "Brian Cryer" wrote:
      [color=blue]
      > "Grigs" <Grigs@discussi ons.microsoft.c om> wrote in message
      > news:D1E3899B-E228-40F7-BA36-2069923FBCC0@mi crosoft.com...[color=green]
      > > Hello,
      > >
      > > I am attempting to write a Web Method in my Web Service that starts a
      > > process that runs the XCOPY command with passed in parameters. It is
      > > failing
      > > on me through code. However, if I take the exact same string it is
      > > passing
      > > and past it into a Command prompt, it works perfectly. That told me it
      > > may
      > > be a permissions/impersonation issue. I am now running it as a special
      > > ServiceAccount I have created that is a Domain Admin. It still does not
      > > work. I then looked to see if it was returning an error or ExitCode and
      > > it
      > > is.
      > >
      > > The ExitCode == 4 which for XCOPY means "Initializa tion error occurred.
      > > There is not enough memory or disk space, or you entered an invalid drive
      > > name or invalid syntax on the command line."
      > >
      > > Here is my code and the output follows - Can anyone help me here? Do I
      > > really need impersonation or is it some other fix?
      > >
      > > FYI: The AddSQLStatement method is simply a way I store information in a
      > > string array for extraction later to determine what happens in my code.
      > >
      > >
      > > string sXCopy = "\"" + sBaseFolder + sSourceFolder + "\"" +
      > > " \"" + sBaseFolder + sDestination + "\"" +
      > > " /E /V /C /I /O /Y /K";
      > >
      > > AddSQLStatement ("XCOPY: " + sXCopy);
      > > AddSQLStatement ("USER: " + System.Environm ent.UserDomainN ame + "\\" +
      > > System.Environm ent.UserName);
      > > AddSQLStatement ("User: " +
      > > System.Security .Principal.Wind owsIdentity.Get Current().Name) ;
      > >
      > > try {
      > > Process oProc = new Process();
      > > oProc.EnableRai singEvents = false;
      > > oProc.StartInfo .FileName = "XCOPY";
      > > oProc.StartInfo .Arguments = sXCopy;
      > > oProc.StartInfo .RedirectStanda rdOutput = true;
      > > oProc.StartInfo .UseShellExecut e = false;
      > > oProc.Start();
      > > AddSQLStatement ("StdOut: " + oProc.StandardO utput.ReadToEnd ()); ////
      > > oProc.WaitForEx it();
      > > AddSQLStatement ("Exit Code: " + oProc.ExitCode. ToString()); ////
      > > } catch(Exception e) {
      > > AddSQLStatement ("XCOPY Error: " + e.ToString());
      > > exLastError = e;
      > > } // try-catch
      > >
      > > <<<<<< This is the output >>>>>>>>
      > >
      > > Exit Code: 4
      > > StdOut: 0 File(s) copied
      > > User: CSDomain\Servic eAccount
      > > USER: CSDOMAIN\Servic eAccount
      > > XCOPY: "\\Cochise\JobF olders\_FolderT emplate"
      > > "\\Cochise\JobF olders\6126_Tes t25e" /E /V /C /I /O /Y /K
      > >
      > > --
      > > Thanx,
      > > Grigs[/color]
      >
      > I may be barking up the wrong tree here, but what is the working directory
      > when you launch xcopy? I seem to recall that dos commands don't take kindly
      > to be kicked off on a share and like the current working directory to be
      > something with a drive letter.
      >
      > Just a thought.
      >
      > Brian.
      >
      > www.cryer.co.uk/brian
      >
      >
      >[/color]

      Comment

      Working...