0

I have an exe file (Console Application). In my ASP.Net I have a page that has a button. On the button click. I wanna start the console application.

Here is my code :

ProcessStartInfo startinfo = new ProcessStartInfo();
            startinfo.FileName = @"C:\PushNotificationSampleConsoleVersion\PushNotificationSampleConsoleVersion\bin\Release\PushNotificationSampleConsoleVersion.exe";
            startinfo.CreateNoWindow = true;
            startinfo.UseShellExecute = true;
            Process myProcess = Process.Start(startinfo);
            myProcess.Start();

When I click the button. nothing happened. I do not see the command prompt window. However when I check my task manager. I see the process started.

Any issue with my code ?

Thanks.

user123456
  • 2,524
  • 7
  • 30
  • 57
  • I suggest you remove both `startinfo.CreateNoWindow = true;` and `startInfo.UseShellExecute = true;` Although it seems a little odd to want a web app to be able to start a console window on the server... – Jon Skeet Apr 11 '16 at 06:10
  • I did. And it is still not showing the window – user123456 Apr 11 '16 at 06:15
  • Ah, got it - presumably it's because you're running under IIS, which I wouldn't expect to be able to interact with the desktop. You may be able to fix that with permissions on the service, but again - are you sure you want anyone clicking on a web site to be able to create a console window on the server's desktop? – Jon Skeet Apr 11 '16 at 06:19
  • no the console window should appear in the local machine where the user is browsing the site. However the exe file will be located in the server. Is that possible ? – user123456 Apr 11 '16 at 13:57
  • No, it's not. Not as a regular console window, certainly. (What would you expect to happen if I'm browsing from a mobile device, or something else that has no concept of a "console window"?) It would be feasible (but a lot of work) to create a sort of "virtual console window" in the browser and communicate with your ASP.NET app over that, which would then communicate with the process. But that's likely to be a huge amount of work - I would think carefully about what you're trying to achieve before doing so. – Jon Skeet Apr 11 '16 at 14:13
  • Actually I have an RDS Database instance. I have created a windows desktop application that will access the db and process some data. When I try to connect to the RDS remotely in the connection string, then connection will fail. I have a clients want to use that desktop application. If i run the exe file in the server, i will work. But I do not want to give my clients access to the server. So I have converted the dektop app to console app. I will host the console app in the server. Then in the website published in the sever. I want him to run that exe from the web page. – user123456 Apr 11 '16 at 14:19
  • If this is a console app that needs interaction, that's going to be painful. If it's a matter of getting some input, running, and then giving some output at the end, then I'd probably do it just in managed code in the original process. But that's now a very long way from what you originally asked. – Jon Skeet Apr 11 '16 at 14:21

1 Answers1

1

To launch an exe from the webpage you should have to do something extra . As browser is not allow to directly look into your file system .This linq may help you . How to launch an EXE from Web page (asp.net)

Community
  • 1
  • 1
avaneesh
  • 31
  • 4
  • I believe the OP is launching the application on the server, not on the client, and I *think* they're aware of that... – Jon Skeet Apr 11 '16 at 06:20
  • @JonSkeet Yes I am running it on the server. – user123456 Apr 11 '16 at 11:27
  • @avaneesh I do not think this a good idea. Since it is not secured. and not happening on button click (it will keep downloading the exe file) – user123456 Apr 11 '16 at 11:30
  • @user123456 I think that you have to create the custom URI and bind your console application to that custom URI and call that URI using your asp.net web page to launch that application . – avaneesh Apr 12 '16 at 05:26