Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi All,

I want to run an Exe file in command prompt with 3 parameters on client system from my c# asp.net website


Here I had used the line of coding in another project for running command prompt in windows application

C#
ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.UseShellExecute = false;
string cocopath = Application.StartupPath;
processStartInfo.WorkingDirectory = cocopath + "\\CocoImport";
processStartInfo.WindowStyle = ProcessWindowStyle.Maximized;
Process process = Process.Start(processStartInfo);

if (process != null)
{
    string a =  txtinput.Text + " -d";
    string b = txtoutput.Text + " -f";
    process.StandardInput.WriteLine("java -jar CocoImport.jar -s " + a + " " + b);

    process.StandardInput.Close(); 

    string outputString = process.StandardOutput.ReadToEnd();
}




Pls help me to resolve this

Thanks & Regards,

Soumya
Posted
Updated 10-Sep-12 4:46am
v3
Comments
[no name] 10-Sep-12 10:53am    
You ever stop to wonder why this is nearly impossible to do? Ever wonder why a user would not want just anyone to run executable files on their system whenever they want?
lewax00 10-Sep-12 11:09am    
You can't. Think about how big of a security risk that would be.
Philip Stuyck 10-Sep-12 11:33am    
do you want to start an application at the server, ie the server where the webserver is running, or at the client ? If it is at the client, better think again.

I completely agree with others(Wes Aday, lewax00, Philip Stuyck)

You must change the way of process. You could do other thing like importing files to server(Browse file from client machine) instead of running exe on client machine.

If still you want do things on client machine then go below....

ActiveX.(Only on IE)

Open_Word_Excel_using_JavaScript[^]
Running activex controls in Mozilla Firefox[^]
 
Share this answer
 
Your code sample has nothing to do with what you are asking about. If you execute anything "from server", it means this is the code executed on the server host, on the server's host processes. As you tag your question "ASP.NET", it means you are running an HTTP service. This service has no access to the processes on any client machine, period. If it could (imagine this theoretically possible situation for a second), 1) the technology could not be called "client-server" :-); 2) the literate users would hardly want to connect to your service, as they would feel totally unprotected from voluntary and unpredictable (for them) behavior or your service: who knows how hard could such service screw up a local system?

Just a note on the code itself:

Even when it works, it's a huge misuse done by many inquirers, not just you, I don't really understand why. This is using "cmd.exe". This is nothing but yet another application, no more. You absolutely don't need it, should directly use "java" command line with the parameter line.

—SA
 
Share this answer
 
Comments
soumyaraj 11-Sep-12 9:57am    
Thank you all for your valuable responses
But the reason behind We choose the web is we want to run it in MAC machine ,but exe will not support over there.so pls let me know the solution
Sergey Alexandrovich Kryukov 11-Sep-12 13:31pm    
I feel you are probably thinking in a wrong direction, but to help you, I would need to have all relevant information starting from your ultimate goals. What exactly do you ultimately want to achieve and why, for what goals?
--SA
Look at Google's native client, far better than Active X and its unpredictable client side dependancies.

https://developers.google.com/native-client/devguide/coding/application-structure[^]

https://developers.google.com/native-client/overview[^]
 
Share this answer
 
Hi sergey,
Thank you for your interest

The following code is working fine in MAC mechine

try
{


ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.UseShellExecute = false;
string folder_name = Server.MapPath(".");

processStartInfo.WorkingDirectory = folder_name;
processStartInfo.WindowStyle = ProcessWindowStyle.Maximized;
Process process = Process.Start(processStartInfo);

if (process != null)
{

string a = folder_name + @"\input";
string b = folder_name + @"\output";
string c = "CTDR";
process.StandardInput.WriteLine("Preview_URL_Generation_Tool_Console.exe " + a + " " + b + " " + c);



process.StandardInput.Close();

string outputString = process.StandardOutput.ReadToEnd();
Response.Write(outputString);
}






}
catch (Exception objException)
{


Response.Write(objException.Message.ToString());
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900