none
C# Windows Service with Process.Start() fails on W2K server

    Question

  • I created a method in a service to open Internet explorer (or any exe), but when I use the System.Diagnostics.Process.Start() method, it doesnt start the application and hangs with no excpetions. I can run the applications properly when I manually execute them, but when using the service and start method I created, it doesnt work. Could it be a permission or security issue? I have to log on to the server and install/run the service. Below is the code:

    System.Diagnostics.Process process = new System.Diagnostics.Process();               
    process.EnableRaisingEvents = false;
    process.StartInfo.FileName = "C:\Program Files\Internet Explorer\IExplorer.exe";
    process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
    process.StartInfo.ErrorDialog = true;

    if (process.Start() == false)
    {
    this.EventLog.WriteEntry("Unable to start proces");
    }
    else
    {
    this.EventLog.WriteEntry("Process started correctyl");
              process.WaitForExit();
    }

    Below is the installer code:

    ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
    ServiceInstaller serviceInstaller = new ServiceInstaller();

    serviceProcessInstaller.Account = ServiceAccount.LocalSystem;           
    serviceProcessInstaller.Username = null;
    serviceProcessInstaller.Password = null;

    serviceInstaller.DisplayName = "My Service";         
    serviceInstaller.StartType = ServiceStartMode.Manual;

    serviceInstaller.ServiceName = "My Service";

    this.Installers.Add(serviceProcessInstaller);
    this.Installers.Add(serviceInstaller);

    Any help would be greatly appreciated.


    Thanks in advance!

    Rico
    Tuesday, April 01, 2008 6:24 PM

Answers

  • First of all, I'd put an @ sign before your string indicating the filename, then I would change the filename from IExplorer.exe to IExplore.exe, which is the proper filename for Internet Explorer.

     

    Secondly, in order to get the service to actually show the UI, you'd have to set the service in Computer Management to allow it to interact with the desktop. In the services window in computer management, go to the properties of your service, and on the Log On tab, check "Allow service to interact with desktop"

     

    Note: This will create a security hole, but it will accomplish what you want.

     

    Tuesday, April 01, 2008 7:09 PM

All replies

  • First of all, I'd put an @ sign before your string indicating the filename, then I would change the filename from IExplorer.exe to IExplore.exe, which is the proper filename for Internet Explorer.

     

    Secondly, in order to get the service to actually show the UI, you'd have to set the service in Computer Management to allow it to interact with the desktop. In the services window in computer management, go to the properties of your service, and on the Log On tab, check "Allow service to interact with desktop"

     

    Note: This will create a security hole, but it will accomplish what you want.

     

    Tuesday, April 01, 2008 7:09 PM
  •  

    Hi Rico, We are also facing the same issue, actually I am calling calc.exe, and I face the same hang issue. Have you got through any solution? Thanks in advance.
    Monday, April 28, 2008 1:32 PM
  • Thanks David, I want to know that what is the security problem with this. If we open the internet explorer directly than it opens with the administrator account. But if allow the Local System log on to the service then the iexplore opend by the service is from local system account, so is there any security issue with that?

     

    Thanks in advance.

     

    Saturday, May 17, 2008 7:12 AM
  • I have the same problem,

    i want to call a batch file when the service is started..

    Hello.bat

    @echo off
    echo Hello World
    pause


    protected override void OnStart(string[] args)
            {
                Process p = new Process();
                p.StartInfo.FileName = @"d:\Temp\Hello.bat";
                p.EnableRaisingEvents = false;
                p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                if (!p.Start())
                    EventLog.WriteEntry("Unable to Start the Process");
                else
                {
                    EventLog.WriteEntry("Process started with no errors");
                    process.WaitForExit();
                }
            }

    when i start the service, it just hangs...

    Am i doing something wrong????

    for now i will try "allow service to interact with desktop" and see if that works out......

    Thursday, May 22, 2008 6:34 PM
  • And is there any way to set "Allow service t ointeract with desktop" by code ?

    Thanks
    RTM
    Saturday, October 04, 2008 6:39 PM
  • Rafa, this is a post disconnected from the original thread.  Please start a new thread if you have a new question.
    David Morton - http://blog.davemorton.net/
    Saturday, October 04, 2008 8:22 PM