C# Windows服务未打开应用程序GUI

C# Windows服务未打开应用程序GUI,c#,winforms,windows-services,C#,Winforms,Windows Services,我正在尝试通过windows服务打开一个应用程序(带有GUI)。它不会抛出任何异常或错误。它没有打开应用程序。 当我在windows窗体应用程序中执行相同的代码时,应用程序正在打开。 为什么windows服务不打开任何其他应用程序? 我的代码如下: protected override void OnStart(string[] args) { try { bool isinstall

我正在尝试通过windows服务打开一个应用程序(带有GUI)。它不会抛出任何异常或错误。它没有打开应用程序。 当我在windows窗体应用程序中执行相同的代码时,应用程序正在打开。 为什么windows服务不打开任何其他应用程序? 我的代码如下:

        protected override void OnStart(string[] args)
        {
            try
            {
                bool isinstalled = checkInstalled("AnyDesk");
                if (isinstalled)
                {
                    Process.Start(@"C:\Program Files (x86)\AnyDesk\AnyDesk.exe");
                }
            }
            catch (Exception ex)
            {
                this.EventLog.WriteEntry(ex.Message, EventLogEntryType.Information);
            }
        }



        public static bool checkInstalled(string c_name)
        {
            string displayName;

            string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
            RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey);
            if (key != null)
            {
                foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
                {
                    displayName = subkey.GetValue("DisplayName") as string;
                    if (displayName != null && displayName.Contains(c_name))
                    {
                        return true;
                    }
                }
                key.Close();
            }

            registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
            key = Registry.LocalMachine.OpenSubKey(registryKey);
            if (key != null)
            {
                foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
                {
                    displayName = subkey.GetValue("DisplayName") as string;
                    if (displayName != null && displayName.Contains(c_name))
                    {
                        return true;
                    }
                }
                key.Close();
            }
            return false;
        }

Windows服务应用程序在与登录用户不同的“窗口站”中运行。您的应用程序正在打开并显示在一个无人能看到的隐藏桌面上


请参阅:

那么,使用windows服务,我们不能打开应用程序吗?如果有的话,还有其他选择吗?你说的隐藏桌面是什么意思?你是说它处于睡眠模式还是关机模式?@CoreTech在你发送的URL中没有我的问题的答案。我的问题是打开另一个应用程序(任何桌面)GUI。不是windows服务GUI(当然不会)。正如@Brent所建议的,windows服务在会话0中运行——一个没有用户可以登录的后台会话。当您的服务启动应用程序时,它在会话0中启动,因此在任何用户的桌面上都不可见。您可以通过查看任务管理器(在“详细信息”选项卡上)来确认您的应用程序正在启动。添加“会话ID”列以查看运行的位置。