473,657 Members | 2,489 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
ProcessArgument s )
{
string ErrorStream = "";
Process DOSProcess = new Process();
ProcessStartInf o StartInfo = new ProcessStartInf o();

StartInfo.FileN ame = @"CMD.exe ";

StartInfo.Redir ectStandardErro r = false;
StartInfo.Redir ectStandardOutp ut = false;
StartInfo.Redir ectStandardInpu t = false;

StartInfo.UseSh ellExecute = false;
StartInfo.Creat eNoWindow = true;

StartInfo.Argum ents = @"/D /c " + ProcessName + " " +
ProcessArgument s;

DOSProcess.Enab leRaisingEvents = true;
DOSProcess.Star tInfo = StartInfo;
DOSProcess.Star t();
DOSProcess.Wait ForExit( 15000 );
int ProcessExitCode = DOSProcess.Exit Code ;

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

DOSProcess.Disp ose();
StartInfo = null;
return ProcessExitCode ;
}

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

I stepped through to check the arguments assigned, I found:
/D /c XCOPY "E:\MySourcedir ectory\Source\B UILDNUMBER\WebR oot"
"E:\MyDestinati onDirectory\Des tination\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:\MySourcedir ectory\Source\B UILDNUMBER\WebR oot"
"E:\MyDestinati onDirectory\Des tination\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.R eadToEnd() it returns empty string.

Where am I going wrong? Any suggestions?

Thanks in advance.

Nov 17 '05 #1
6 22500
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.c om> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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.c om> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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.c om> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.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.c om> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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
1739
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 the second error the error is reported by the function that called myFunctionXYZ, Function DooDah. Example: Function DooDah() on Error goto ErrorRoutine
3
1407
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) return 3; // 3 may mean a specific error .... return 0; // 0 == successful
4
3616
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 fastest/easiest way to do that? MTIA wardeaux
0
3445
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 what your resolution was? This is the complete error message. Error in OnFinish: Failed to return new Code Element. Possibly syntax error. New Element Name - (name of my object library including the complete path )
6
3777
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 error... Failed to return new Code Element. Possibley syntax error. New Element Name. Temp123 I recently changed the name of the cpp file (using Solution Explorer) of this class. Since that change, the error always occurs. I attempted to...
1
1299
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
848
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 Code window to be the active one after returning from the debug/running app?, and (b) if not, then is there a way to get to the Code window with a keystroke (right now, I have to pick up the mouse every time and click on the code window) ...
2
1480
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 i need to get the value out the same way i decide to use whats already there. The problem is it works for the original one and breaks for the new one. My code is bellow. It seems to break on theform.elements.value. it does not like id i think.Like i...
1
1695
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 values "(224 238 223)" in "model1.jpg". thanks for your help. Code : import Image model1 = Image.open("model1.jpg") test = Image.open("test.jpg") im = Image.new("RGB",(500,500))
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8726
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6163
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.