Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, from a service you can run code on the desktop... The matter is on which desktop? because there may be various users logged at the same time (for example in a Windows Server there may be various users logged remotely).</p> <p>If use <code>Process.Start</code> from a service as in your example:</p> <pre><code>System.Diagnostics.Process.Start("www.google.com"); </code></pre> <p>The program will not appear in the desktop of any user, because the service is not associated with any of the desktops of the users.</p> <hr> <p>The solution is to detect which user is logged locally and then execute the program as that user (and under the privileges of that user). For that I want to link you to <a href="https://stackoverflow.com/a/12851218/402022">another of my answers</a> where I demonstrate how to invoke a program from a service. <strong>In <a href="https://stackoverflow.com/a/12851218/402022">that answer</a> I present the code needed for this technique</strong>.</p> <p><em>Note</em>: That answer was about an screen capture, still the technique I describe is to call a program in the session of an user, and that method works from a service. So it applies to your problem.</p> <p>You can use this method to execute the desired browser directly. As an alternative you can use it to invoke your service executable, where you can use <a href="http://msdn.microsoft.com/en-us/library/system.environment.userinteractive.aspx" rel="nofollow noreferrer"><code>System.Environment.UserInteractive</code></a> to detect if the executable is not running as a service or not. If you pass the url as execution argument to your service executable then you can open it with the default browser using <a href="http://msdn.microsoft.com/en-us/library/system.environment.userinteractive.aspx" rel="nofollow noreferrer"><code>Process.Start</code></a> just like your example above.</p> <p><em>Note</em>: The code was tested on Windows 7.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload