使用C#刷新所有浏览器的Windows服务
本文关键字:Windows 服务 浏览器 刷新 使用 | 更新日期: 2023-09-27 18:27:27
我创建了一个windows应用程序,用于刷新客户端机器中所有打开的浏览器。这是链接需要使用C#刷新chrome浏览器
现在我已经将该windows应用程序转换为windows服务,但问题是它不起作用,因为在我的windows应用程序中,我正在根据任务管理器中运行的进程刷新浏览器,我认为在windows服务中,它无法识别任何进程。
这似乎是因为权限。当您运行windows应用程序时,它将以当前登录用户的权限运行。当您将其配置为windows服务时,您使用了哪个帐户?尝试以管理员身份运行windows服务。
最简单的解决方案是使用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");