473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Alternatives to cmd.exe in C# application

Hi,

To run all commands from C# application i creates Process class in which main process i am passing as an arguments to cmd.exe as given below:

ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", @"/c myapp.pl");
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.LoadUserProfile = true;
//provided domain/user name and password also
Process proc = new Process();
proc = Process.Start(psi);

But this will create two processes cmd.exe and myapp.pl. Is there any alternative to cmd such that it will create only myapp.pl. or is there any switch that can be use with cmd such that it will not create cmd.exe window.

Please not that i am providing user/domain and password and thus psi.loadUserProfile is true and because of this it will definately creat new window as process will be run in the new security user context.

Thanks
Paresh
Apr 9 '08 #1
8 10841
Plater
7,872 Expert 4TB
I already told you before:
ProcessStartInfo psi = new ProcessStartInfo("myapp.pl", "");

There is NO reason to invoke cmd.exe to begin with.

And in the example you just provided, a cmd window would no be created as a result of your code, however is the program you invoke ALSO invokes another program, you have no control over whether or not THAT window will be created.
Apr 9 '08 #2
Hey Plater,

There is the obvious reason that i am invoking all the commands through the cmd.exe because like this only i can spawn any types of processes having any extensions like .msc, .cpl, .exe, .pl, .bat which might not be Win32 application which is only supported by C# Process class. and also i have to use Process class as i am creating process in the new context of the user by provising user/domain name and password.

Hopes you could get this now.

Thanks,
Paresh
Apr 9 '08 #3
Morever the new window will definately be created because of LoadUserProfile is being true in Process class and i am giving user credential together to create new process.

Thanks,
Paresh
Apr 9 '08 #4
Plater
7,872 Expert 4TB
There is the obvious reason that i am invoking all the commands through the cmd.exe because like this only i can spawn any types of processes having any extensions like .msc, .cpl, .exe, .pl, .bat which might not be Win32 application which is only supported by C# Process class.
And I keep telling you that is not a true statement.
The Process class can run anything that can be put into the Run dialog from the start menu.
Technically perl and php and other scripts get run through an interpreter program and have to be "set up" to use that. But if you didn't have those things setup, you couldn't invoke them as an argument to cmd.exe either.
Apr 9 '08 #5
Please see the error when i run program in following way:

ProcessStartInfo psi = new ProcessStartInfo(@"c:\local\interactive.pl", "");
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
proc = Process.Start(psi);

C:\>c:\local\InteractiveScript\bin\Release\Interac tiveScript.exe
The specified executable is not a valid Win32 application.

Any comments??

Thanks,
Paresh
Apr 9 '08 #6
Plater
7,872 Expert 4TB
Well I see:
ProcessStartInfo psi = new ProcessStartInfo(@"c:\local\interactive.pl", "");
and
C:\>c:\local\InteractiveScript\bin\Release\Interac tive Script.exe

Which is it?
And I would probably guess it's because you have useshellexecute turned off (which gets negated when you run through CMD because it uses a shell execute statement to run it)
Apr 9 '08 #7
InteractiveScript.exe is the C# application's executable which runs interactive.pl perl script.

I have to ser UseShellExecute to false as i am redirecting the input/output and also i am using UserLoadProfile = true to give the user credential to run interactive.pl in the context of user.


Thanks,
Apr 10 '08 #8
Plater
7,872 Expert 4TB
Setting UseShellExecute to false means that it won't look up file extension associations. Such as mapping .pl to the perl proccessor, BMP to the default handler.
Forcing it to only run valid win32 EXEs.
CMD.EXE is a valid Win32 application.
Giving CMD the argument tells CMD to run the program, but it's allowed to use a SHELLEXECUTE to look up the default handler for the file type.
Which is why in CMD you can type "mybmp.bmp" and the default handler for BMP files will run the file just as if you had double clicked in the window.

ShellExecute has no bearing on redirecting stdio. As to the user profile stuff, I am unsure, but I would doubt it.
Apr 10 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Miles Davenport | last post by:
I would like some advice on what Java server-side alternatives their are to an applet which is a shopping cart application which allows the user to drag-and-drop individual items into "an order"...
2
by: Rob van der Putten | last post by:
Hi there Are there any alternatives for Fop that support Docbook? I'm having problems with <screen> ... </screen>. It's too wide, even though none of the screen dumps is wider than 80 chars....
3
by: Dan Christensen | last post by:
I have written a small application in VB6 -- a kind of special purpose text editor. There seem to be many annoying glitches in VB's rich text box control, however. Performance on larger files has...
2
by: Guadala Harry | last post by:
The current implementation (that works) retrieves data from a SS2K db via stored procedure that returns 40-60 rows and 6 columns (one string and five int columns), and places that result set into a...
1
by: John Lee | last post by:
Hi, I do not know where is the best place to post this type of question - everytime in this case I always choose this group because I think we have a lots of genius here in this group -...
1
by: Charles Rumbold | last post by:
We have a .Net web form application using a SqlServer database. Part of the app is/will be a background process that wakes up every so often to do some things (say every 5 minutes to process a...
4
by: Eduard Witteveen | last post by:
Hello, I want to store (database-)data on my local machine. Traditionally would choose to use a ms-access database to store my information. -> Is the choosing ms-access a good idea? (do i need...
6
by: greek_bill | last post by:
Hi, I'm interested in developing an application that needs to run on more than one operating system. Naturally, a lot of the code will be shared between the various OSs, with OS specific...
7
by: phreaker | last post by:
Hi, I'm interested in the alternatives to debugging C# other than Visual Studio .NET I have a large multi-threaded application, and I find that the debugger that comes with Visual Studio...
1
by: Spencer | last post by:
Our Mainframe DBA insists that the IDTHTOIN parameter be set to 600 so that all idle threads timeout after 10 minutes. This is causing a particular packaged application that expects to hold idle...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...

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.