Solved

Process.Start "Access is denied" exception

Posted on 2008-11-03
14
2,682 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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
 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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