Process Problems - XCOPY ExitCode

Discussion in 'ASP .Net' started by =?Utf-8?B?R3JpZ3M=?=, May 25, 2005.

  1. 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 "Initialization 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.Environment.UserDomainName + "\\" +
    System.Environment.UserName);
    AddSQLStatement("User: " +
    System.Security.Principal.WindowsIdentity.GetCurrent().Name);

    try {
    Process oProc = new Process();
    oProc.EnableRaisingEvents = false;
    oProc.StartInfo.FileName = "XCOPY";
    oProc.StartInfo.Arguments = sXCopy;
    oProc.StartInfo.RedirectStandardOutput = true;
    oProc.StartInfo.UseShellExecute = false;
    oProc.Start();
    AddSQLStatement("StdOut: " + oProc.StandardOutput.ReadToEnd()); ////
    oProc.WaitForExit();
    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\ServiceAccount
    USER: CSDOMAIN\ServiceAccount
    XCOPY: "\\Cochise\JobFolders\_FolderTemplate"
    "\\Cochise\JobFolders\6126_Test25e" /E /V /C /I /O /Y /K

    --
    Thanx,
    Grigs
     
    =?Utf-8?B?R3JpZ3M=?=, May 25, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?R3JpZ3M=?=

    Brian Cryer Guest

    "Grigs" <> wrote in message
    news:D...
    > 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 "Initialization 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.Environment.UserDomainName + "\\" +
    > System.Environment.UserName);
    > AddSQLStatement("User: " +
    > System.Security.Principal.WindowsIdentity.GetCurrent().Name);
    >
    > try {
    > Process oProc = new Process();
    > oProc.EnableRaisingEvents = false;
    > oProc.StartInfo.FileName = "XCOPY";
    > oProc.StartInfo.Arguments = sXCopy;
    > oProc.StartInfo.RedirectStandardOutput = true;
    > oProc.StartInfo.UseShellExecute = false;
    > oProc.Start();
    > AddSQLStatement("StdOut: " + oProc.StandardOutput.ReadToEnd()); ////
    > oProc.WaitForExit();
    > 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\ServiceAccount
    > USER: CSDOMAIN\ServiceAccount
    > XCOPY: "\\Cochise\JobFolders\_FolderTemplate"
    > "\\Cochise\JobFolders\6126_Test25e" /E /V /C /I /O /Y /K
    >
    > --
    > Thanx,
    > Grigs


    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
     
    Brian Cryer, May 25, 2005
    #2
    1. Advertising

  3. 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:

    > "Grigs" <> wrote in message
    > news:D...
    > > 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 "Initialization 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.Environment.UserDomainName + "\\" +
    > > System.Environment.UserName);
    > > AddSQLStatement("User: " +
    > > System.Security.Principal.WindowsIdentity.GetCurrent().Name);
    > >
    > > try {
    > > Process oProc = new Process();
    > > oProc.EnableRaisingEvents = false;
    > > oProc.StartInfo.FileName = "XCOPY";
    > > oProc.StartInfo.Arguments = sXCopy;
    > > oProc.StartInfo.RedirectStandardOutput = true;
    > > oProc.StartInfo.UseShellExecute = false;
    > > oProc.Start();
    > > AddSQLStatement("StdOut: " + oProc.StandardOutput.ReadToEnd()); ////
    > > oProc.WaitForExit();
    > > 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\ServiceAccount
    > > USER: CSDOMAIN\ServiceAccount
    > > XCOPY: "\\Cochise\JobFolders\_FolderTemplate"
    > > "\\Cochise\JobFolders\6126_Test25e" /E /V /C /I /O /Y /K
    > >
    > > --
    > > Thanx,
    > > Grigs

    >
    > 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
    >
    >
    >
     
    =?Utf-8?B?R3JpZ3M=?=, May 25, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Roberts
    Replies:
    0
    Views:
    740
    Mark Roberts
    Jul 2, 2003
  2. Cristian Suazo

    Problem when deploying with xcopy

    Cristian Suazo, Jul 16, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    470
    the Dude
    Jul 16, 2003
  3. Ali Nikzad

    XCopy

    Ali Nikzad, Aug 11, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,130
  4. Matt Anderson

    Xcopy deployment drops user connections

    Matt Anderson, Aug 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    380
    S. Justin Gengo
    Aug 18, 2003
  5. Matthew Lee

    Permissions Issues: Process.Start() & XCOPY

    Matthew Lee, Jun 8, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,672
    Matthew Lee
    Jun 8, 2004
Loading...

Share This Page