Solved

Process.Start "Access is denied" exception

Posted on 2008-11-03
14
2,669 Views
Last Modified: 2008-12-10
When I run this code it will start the cmd process twice then the third time it gives an unhandled exception "Access is denied".  What is going on and how do I fix it?
string pram = "";

            for (int i = 0; i < 4000; ++i)

            {

                pram += 'i';

                if(pram.Length > 2050)

                Process.Start("cmd.exe", pram);

            }

Open in new window

0
Comment
Question by:turn123
  • 7
  • 7
14 Comments
 
LVL 11

Author Comment

by:turn123
ID: 22868387
Using VS 2008 to compile and OS is XP Pro if it makes any difference.
0
 
LVL 41

Expert Comment

by:graye
ID: 22868675
CMD has a maxium size for a "command line" at about 8k...   What are you trying to do?
0
 
LVL 11

Author Comment

by:turn123
ID: 22869362
I'm passing an XML file to another program as a command line argument to be parsed and printed.

Basically I'm trying to get the same functionality as an existing Perl script that calls it with the system command.

Is there another way I should be doing this?
system "PrintInvoiceVer.exe $xml";

Open in new window

0
 
LVL 41

Expert Comment

by:graye
ID: 22870066
Pardon me, but what the heck does that have to do with the sample you posted.... I'm very confused.
Try this:   "cmd /c PrintInvoiceVer.exe " & xmlfilenamevariable
0
 
LVL 11

Author Comment

by:turn123
ID: 22885169
The example I posted was an a test case showing where the problem was occurring.  The second example is was what the current program I am replacing is doing that works.  It seems that both should work.

Anyway when I try your suggestion I'm getting a compile error.

"Operator '&' cannot be applied to operands of type 'string' and 'string'"
0
 
LVL 41

Expert Comment

by:graye
ID: 22887171
Ooops, try "+"
0
 
LVL 11

Author Comment

by:turn123
ID: 22887234
Now it is throwing an unhandled exception "The system cannot find the file specified"
string pram = "";

            for (int i = 0; i < 4000; ++i)

            {

                pram += 'i';

                if (pram.Length > 2050)

                    Process.Start("cmd /c PrintInvoiceVer.exe " + pram);

            }

Open in new window

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 41

Expert Comment

by:graye
ID: 22889218
Because there is no file called iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
Again, that's a very strange example.    I don't understand what that example has to do with anything... are you testing the length of the items you can put in a command line?
0
 
LVL 11

Author Comment

by:turn123
ID: 22889247
There is no file called


<?xml version="1.0" ?>
<QBXML>
<QBXMLMsgsRs>
<InvoiceQueryRs statusCode="0" statusSeverity="Info" statusMessage="Status OK">
<InvoiceRet>
<TxnID>39C6BB-1220637230</TxnID>
<TimeCreated>2008-09-05T13:53:50-05:00</TimeCreated>


either.  This is part of the parameter I'm trying to pass to a command line program so that it can process it.  It doesn't seem to matter what I pass.  Once it exceeds a certain length I get the access is denied error when using process.start.

When I try using the example you gave it says it can't find the file.
0
 
LVL 41

Expert Comment

by:graye
ID: 22891107
Wow.... Now, I know I'm totally lost.  
Let's start from the very beginning and have you describe what the heck you're trying to do.  Please don't  give us an example of what you've tried so far... that's obvioulsy not helping much.   Instead concentrate on a bettter description of the problem
0
 
LVL 11

Author Comment

by:turn123
ID: 22894056
Ok I have a program that excepts a command line argument of an XML file.  I am trying to start this program and pass it the XML file as an argument.
0
 
LVL 41

Accepted Solution

by:
graye earned 250 total points
ID: 22894368
So, write the XML data to a file, and then use that file name as an argument when doing a Process.Start
"PrintInvoiceVer.exe " + TheNameOfTheFileYouCreatedThatHasTheXMLDataInIt
The name of the file should make the command line too long.... it'd be something like this:
PrintInvoiceVer.exe C:\Temp\SomeFile.xml
0
 
LVL 41

Expert Comment

by:graye
ID: 22894375
dang.... I missed a word
The name of the file should NOT make the command line too long.... it'd be something like this:
0
 
LVL 11

Author Comment

by:turn123
ID: 22894433
That's basically what I'm doing now.  I would prefer not to have to write a file if that is possible to do.  I'm thinking there should be a way to do it without writing a file as I can do it in Perl without having to write a file.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Aspnet xml 2 36
Unit testing, moq, best practices 7 29
Using MS Code on my Mac 6 47
Image(2) 3 29
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now