【问题标题】:Windows service for Refreshing all browser using C#使用 C# 刷新所有浏览器的 Windows 服务
【发布时间】:2014-10-22 06:48:00
【问题描述】:

我创建了一个 Windows 应用程序,用于刷新客户端计算机中所有打开的浏览器。 链接在这里 Need to refresh chrome browser using C#

现在我已将该 windows 应用程序转换为 windows 服务,但问题是它无法正常工作,因为在我的 windows 应用程序中,我正在根据任务管理器中运行的进程刷新浏览器,而我认为在 windows 服务中它无法识别任何进程。

【问题讨论】:

    标签: c# asp.net windows windows-services browser


    【解决方案1】:

    似乎是因为权限。当您运行 Windows 应用程序时,它将以当前登录用户的权限运行。当你把它配置为windows服务时,你用的是哪个帐号?尝试以管理员身份运行 Windows 服务。

    【讨论】:

    • 我如何以管理员身份运行我的服务,我正在以管理员身份运行 Visual Studio。
    • @asifiqbal 请用谷歌搜索。您还可以参考现有线程,例如stackoverflow.com/questions/22888712/…
    【解决方案2】:

    最简单的解决方案是使用Topshelf 将您的应用程序转换为Windows 服务。示例初始化调用如下所示:

            HostFactory.Run(x =>
                {
                    x.Service<MyServiceHost>(s =>
                        {
                            s.ConstructUsing(name => new MyServiceHost());
                            s.WhenStarted(tc => tc.Start());
                            s.WhenStopped(tc => tc.Stop());
                        });
                    x.DependsOnEventLog(); // Windows Event Log
                    x.DependsOnIis(); // Internet Information Server
                    x.StartAutomaticallyDelayed();
    
                    x.EnablePauseAndContinue();
                    x.EnableShutdown();
                    x.EnableServiceRecovery(rc =>
                        {
                            rc.RestartService(1); // restart the service after 1 minute
                            rc.SetResetPeriod(1); // set the reset interval to one day
                        });
    
                    x.RunAsLocalSystem();
    
                    x.SetDescription("The My Service provides services to the My Webspace web application that require elevated privileges, such as creating customer websites in IIS.");
                    x.SetDisplayName("My Service");
                    x.SetServiceName("MyService");
                });
    

    在此示例中,服务作为本地 SYSTEM 帐户运行。其他选项包括:本地服务、网络服务、提示输入凭据或使用显式用户名/密码(可能从您的配置文件中读取),例如x.RunAs("username", "password");

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-23
      • 2014-12-10
      • 1970-01-01
      • 2020-06-30
      • 2012-04-17
      • 2021-04-22
      • 2022-10-19
      • 1970-01-01
      相关资源
      最近更新 更多