Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI of Process is not visible after Process.Start()

Tags:

c#

wcf

I have made a WCF Service and it contains a method string SaveVideoInformation()

The purpose of this method is to run a process if it is not running. Following is the code of that method.

 public string SaveVideoInformation(string ID, string videoName)
    {
        string Result = null;
        try
        {
            Result = Insert(ID, videoName);
            Process[] pname = Process.GetProcessesByName("AutoRunVideoWaterMarkingTook");
            if (pname.Length == 0)
            {
                Result += " | Trying to run Process";
                try
                {
                    Process process = Process.Start(@"~\Debug\AutoRunVideoWaterMarkingTook.exe");
                    Result += " | Process Ran Successfully";
                }
                catch (Exception ex)
                {
                    Result += " | Exception While Running the process";
                    throw new Exception("Unable to start Process);
                }
            }
            else
            {
                Result += "|Process Already Running";
            }
        }
        catch (Exception ex)
        {
            Result = "Not Done," + ex.Message;
        }
        return Result;
    }

The problem I am facing is when i call this method from Windows Form Tool Application, it run successfully and i can see the UI.

but when i call this method from Windows Service, Process Starts but its UI is not visible.

like image 221
Charlie Avatar asked Feb 22 '16 10:02

Charlie


1 Answers

That is most likely because your Windows Service is not in user interactive mode.

You have to enable this from the Services panel, as described in this blog: Check the Allow service to interact with desktop in the service properties Log On page.

Also read Microsofts recommendations on user interactive services.

like image 141
Patrick Hofman Avatar answered Oct 08 '22 22:10

Patrick Hofman