How to launch process in c#.net web application(on button's click event)

 

Hi All,

 

using System.Diagnostics;

Process process = new Process();

process.StartInfo.FileName ="msimn.exe";

process.Start();

This code runs perfectly with Console Application but I need to run  same " msimn.exe" on button's click event in web application..I have tried but unable to do that..

Pls..let me know how to do that ,Thanks in advance

Leena

 

 

 




Answer this question

How to launch process in c#.net web application(on button's click event)

  • Anthony Alvarado

    Leena,

    iam trying to run a batch file from c# app.. it runs perfectly from console... but iam trying to make it a window service (the application is a file watcher)   and now its not runing at all

     

    any idea



  • xcv

    Hi Guys,

    Got some how similiar link to solve problem  i.e.

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=100749&SiteID=1,
     
    but still donot know, How to run exe from client side on button's click event i.e computer that is viewing the web page

    My exe is present on each and every client and  Location where it resides is also same  i.e C:\Program Files\xyz\.........



  • Kwanhong Young

    Leena,

    I'm still confused. From which computer should the application be uninstalled from The computer hosting the web page or the computer that is viewing the web page



  • MarkHarris

    You could copy the file from the server share to a temp directory on the client machine, then execute it and delete it once execution has completed.

    string strSourceFile = @"\\server\share\filename.exe";

    string strDestinationFile = Environment.GetEnvironmentVariable("TEMP") + @"\filename.exe"

    File.Copy(strSourceFile, strDestinationFile, true)  // the true is a bool value to overwrite if exists

    Process myProcess = new Process();

    myProcess.Start(strDestinationFile);

    myProcess.WaitForExit();

    File.Delete(strDestinationFile);

    I hope this helps you.

    Nathan


  • Andrew Piper

    So how is it done indirectly

    We have the same issue. Our users have installed say program A, B and C locally and want to see icons for these programs on a page on our intranet. They want to click and start these programs from the icons instead of finding these programs in the start menu.

    I once did this through an ActiveX component. What I didn't implement was a way to white list programs the component could start in case someone wanted to run format c: or something. So I removed it and I'am wondering how I can write a similar component, but this time in C#.

    Cheers,

    Kjell Inge



  • Daniel Corbett

    It sounds like you are trying to execute code on the clients machine from a web page. You cannot do this directly and you should not try to do this. If you need to uninstall something, you need to have the user download the exe and then run it locally on their machine manually.


  • f00biebletch

    What are you trying to achieve Do you want to run the application on the client or server side

    If its the former, you won't be able to do that as the Process code runs on the service side. If you are trying to start up Outlook Express for emailing purposes try using the mailto protocol, for example: mailto:mail@mydomain.com

    If its the later, this is typically a very bad idea, imagine if a hundred users pushed the button at the same time; you have a very 'denial of service' attack waiting to happen.



  • Cesar Estrada

    Hi Leen

    I dont know if this is a good idea but one of the ways to do this is create a Managed C++ class that has a public function receiving a system command. In this public function you excute the system command by calling the C system() function.  Compile this class to a DLL and reference this DLL from your C# application to call the Manages C++ public function directly. By doing this, you can activate your EXE from a button click. 

     

    Declaration:

    int system(const char *string);

    The command specified by string is passed to the host environment to be executed by the command processor. A null pointer can be used to inquire whether or not the command processor exists.

    If string is a null pointer and the command processor exists, then zero is returned. All other return values are implementation-defined.


  • CSved

    Hi David,
     I have taken example of outlook express...Actually we have some.exe which uninstalls some software which are no more required.
    Right now we are manually running that exe, (& Do not want our end users to access that exe)
    I want anybody who clicks the button on webpage, that exe should be run and uninstall respective software from that machine.
    How to achieve this, is there any other way to do that
    Thanks
    Leena


  • JD Li

    Thanks the code snippet was helful for me



  • How to launch process in c#.net web application(on button's click event)