473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 "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.GetCurre nt().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
Nov 19 '05 #1
2 2184
"Grigs" <Gr***@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
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.GetCurre nt().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
Nov 19 '05 #2
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" <Gr***@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
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.GetCurre nt().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

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jam | last post by:
Dear All, I have a command process running xcopy in console, and now I want to execute the program Rsync After the files are copied...how could i do?? Process p10=new Process();...
7
by: Samantha | last post by:
Hello , I am developping a program for Win98 plateform, and I am stucking with a problem, hope you can help me. I have a program running 2 process : - One process running the Xcopy.exe -...
10
by: Tony | last post by:
I am running an application called AcroComm.exe to poll time clocks here at our company. I have written a small C# app that will poll the clocks based on information found in a DB. My problem is...
4
by: Christian Billig | last post by:
Hi, well i've a problem and i don't know how to solve it. I wrote a function, which starts a Process for a user by using the API CreateProcessWithLogon. Afterwards i want to know if the...
11
by: Nurit N | last post by:
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...
4
by: Andy | last post by:
I am calling out to an executable using the System.Diagnostics.Process methods and specifically attempting to trap for errors (at least trying to learn how to trap for errors). I arranged the data...
1
by: tenpsa | last post by:
Hi, I have a C# application that uses the System.Diagnostics.Process functionality to execute other processes (to install a couple of .msi files). Here's my code so far: ...
2
by: =?Utf-8?B?U3RldmVU?= | last post by:
I am trying to get the exit code of an application (IE) after the process closes. On my system I keep getting an exception error. "No process is associated with the object." The Process class is...
1
by: vinayakkatkam | last post by:
public bool ProcessXCopy() { string XCopyArguments = "C:\\Documents and Settings\\Vinayak.Katkam\\Desktop\\SYNCHRONIZATION\\BASE-VERSION\\SDDS\\*.* " + "C:\\Documents and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.