473,507 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XCOPY return ExitCode 4 in C# code.

I am developing a ASP.Net(Web) based deployment tool, which requires
XCOPY functionality.

Here is the code for the method:

public static int ExecuteProcess ( string ProcessName, string
ProcessArguments )
{
string ErrorStream = "";
Process DOSProcess = new Process();
ProcessStartInfo StartInfo = new ProcessStartInfo();

StartInfo.FileName = @"CMD.exe ";

StartInfo.RedirectStandardError = false;
StartInfo.RedirectStandardOutput = false;
StartInfo.RedirectStandardInput = false;

StartInfo.UseShellExecute = false;
StartInfo.CreateNoWindow = true;

StartInfo.Arguments = @"/D /c " + ProcessName + " " +
ProcessArguments;

DOSProcess.EnableRaisingEvents = true;
DOSProcess.StartInfo = StartInfo;
DOSProcess.Start();
DOSProcess.WaitForExit( 15000 );
int ProcessExitCode = DOSProcess.ExitCode ;

if ( ProcessExitCode > 0 & !DOSProcess.HasExited )
DOSProcess.Kill();

DOSProcess.Dispose();
StartInfo = null;
return ProcessExitCode;
}

ExecuteProcess method takes ProcessName (in my case: XCOPY) and
ProcessArguments (in my case: the arguments needed for the XCOPY)

I stepped through to check the arguments assigned, I found:
/D /c XCOPY "E:\MySourcedirectory\Source\BUILDNUMBER\WebRo ot"
"E:\MyDestinationDirectory\Destination\web" /S /E /F /H /R /Y /i

These are the switches I am passing for XCOPY: /S /E /F /H /R /Y /i

This runs excellent when I directly run from Command line as: cmd.exe
/D /c XCOPY "E:\MySourcedirectory\Source\BUILDNUMBER\WebRo ot"
"E:\MyDestinationDirectory\Destination\web" /S /E /F /H /R /Y /i

The program first calls this method to back up existing files and then
copies the new files to the location. Back up works well but deployment
it does not do anything and returns exit code: 4.

According to MSDN, ExitCode 4 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.

As I mentioned, this runs smoothly from commandline.

When I use StandardError.ReadToEnd() it returns empty string.

Where am I going wrong? Any suggestions?

Thanks in advance.

Nov 17 '05 #1
6 22494
i think this is a permission issue. asp.net is not a previlliged user. can
you try to run the same code in a console or windows application? it seem to
work ok. if so, you will give asp.net account required permissions.
Nov 17 '05 #2
Thank you Crow for your response.

The application uses Window authentication. And if I understand
correctly, the permissions will be same as the user.

Also, the same works in one case and returns ExitCode 4 in the other.

Nov 17 '05 #3
No it wont, the spawned CMD will use the identity of your asp worker
process, not the identity of the impersonated user.
"Zeya" <ze****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Thank you Crow for your response.

The application uses Window authentication. And if I understand
correctly, the permissions will be same as the user.

Also, the same works in one case and returns ExitCode 4 in the other.

Nov 17 '05 #4

Willy Denoyette [MVP] wrote:
No it wont, the spawned CMD will use the identity of your asp worker
process, not the identity of the impersonated user.
"Zeya" <ze****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Thank you Crow for your response.

The application uses Window authentication. And if I understand
correctly, the permissions will be same as the user.

Also, the same works in one case and returns ExitCode 4 in the other.

Thanks Willy. But I am not fully convinced. Reason being that I am able
to do a XCOPY in another subdirectory of the parent directory and it
works fine. (This happens when I am backing up the current files). If
the backup process could be executed with no issues then deploying is
the same process.

Would you have any other method that I could use to do this?

Nov 17 '05 #5

"Zeya" <ze****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

Willy Denoyette [MVP] wrote:
No it wont, the spawned CMD will use the identity of your asp worker
process, not the identity of the impersonated user.
"Zeya" <ze****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
> Thank you Crow for your response.
>
> The application uses Window authentication. And if I understand
> correctly, the permissions will be same as the user.
>
> Also, the same works in one case and returns ExitCode 4 in the other.
>

Thanks Willy. But I am not fully convinced. Reason being that I am able
to do a XCOPY in another subdirectory of the parent directory and it
works fine. (This happens when I am backing up the current files). If
the backup process could be executed with no issues then deploying is
the same process.

Would you have any other method that I could use to do this?


If you are not convinced by what I'm saying (it's perfectly acceptable to be
sceptic ;-)) you can convince yourself by looking for the identity of the
CMD process in taskman when it runs your XCOPY.
This asside, when it works you are reading from the home directory and
writing into another subdir of the home dir. It's when you try to write into
the home dir that it fails, right? Well the you need to check the access
privileges and look if aspnet or whtever the identity of the CMD process may
be has writte permissions for that home directory.
Willy.
Nov 17 '05 #6
Willy,

I did not mean to be offensive by saying I am not convinced and I
absolutely appreciate your help.

However, I dropped the idea of using XCOPY instead I used Robocopy and
it worked like a charm.

So, again thanks for your help.

Nov 17 '05 #7

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

Similar topics

1
1729
by: laurenq uantrell | last post by:
I'm trying to figure out why I can't loop through a function (myFunctionXYZ) after an error. The problem is that I can loop from the error once back into the code section of myFunctionXYZ, but on...
3
1402
by: RafaelC | last post by:
hello, I'm new to C# so forgive me for a simple/silly question. In C/C++ you can return a different code number if an error has occurred, for example: int main() { .... if (someError)...
4
3604
by: Wardeaux | last post by:
Hope this is easy... I have a simple winform app that does some work and then exits... I need to return a value to the calling app/process to indicate completion status... what's the...
0
3433
by: vcuser | last post by:
All, Can someone please let me know if you have come across this error in VC 7.1 when trying to implement an interface using the "Implement Interface wizard"? If so, can you please let me know...
6
3762
by: RML | last post by:
Hi, I have a VS2005 VC++ application which no longer allows me to add a Variable or Function to a class in the project. I attempt to add a new (public) Variable called Temp123, and get this...
1
1293
by: lisek | last post by:
I am looking for function witch retrurn string witch code of www site. For example. Site www.something.com/index.htm] look's like: <meta> </meta> <body> something something </body>
0
843
by: bob | last post by:
After running the application and quitting, vb.net returns me to the "Properties" window instead of the "Code" window, which is where I want to be most of the time. (a) Is there a way to force the...
2
1468
by: Taftheman | last post by:
Hi, I have created a pop up using js and returns a value for me to process. I have got it working. I now need to do it again for another button. The value return will be processed differently. But as...
1
1688
by: sbtunx | last post by:
The problem is that the "if-else" command doesn't work properly. the program always returns entire "else" commands means all black pixels in end.bmp . but there is some pixels that have the same...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
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
7482
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...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.