Solved

Shell Commands using Process Info in System.Diagnostics

Posted on 2010-09-04
4
484 Views
Last Modified: 2012-05-10
Hey experts,

I'm writing a simple program in C# to loop through an XML file and execute commands one after the other on a machine. The primary purpose of this application is to automated a number of deployment steps.

I'm using ProcessInfo and Process in the .NET library and using C# as the language.

Problem:
-------------

I'm unable to execute DOS/Shell commands using ProcessInfo object. Simple exe's, bat's etc work, but when trying o execute a system specific shell command doesn't work.

Examples:
---------------

As an example:

1. Install.exe C:\Program Files\..... works
2. del c:\Program Files\....\abcd.txt doesn't work

So my question is:

How do you execute such DOS commands like del, dir etc using the System.Diagnostics classes in .NET.

I'm open to other namespaces as well in .NET as well as other free tools to get the job done.

0
Comment
Question by:kunal_chopra28
4 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33604001
0
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33605880
if(System.IO.File.Exists("c:\Program Files\....\abcd.txt"))
System.IO.File.Delete("c:\Program Files\....\abcd.txt");
0
 
LVL 5

Accepted Solution

by:
andr_gin earned 250 total points
ID: 33610535
The reason why you cant execute del C:\testfile.txt is that there is not del.exe that you can execute.
del is an internal command of the command line.

You can execute internal commands bei calling:
cmd /c del C:\testfile.txt

This starts the Process cmd.exe which uses its internal command del to delete the file.
0
 

Author Closing Comment

by:kunal_chopra28
ID: 33618460
Thank you for the comments and answer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c# string handling 1 26
Q2. How to run DAX query from SSMS. I don’t see any DAX query type. 1 46
Two different visual studio versions 3 22
Server Error 11 47
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

914 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

14 Experts available now in Live!

Get 1:1 Help Now