如何从 Windows 服务启动浏览器 [英] How can I start a browser from a windows service

查看:50
本文介绍了如何从 Windows 服务启动浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个在启动时打开特定 URL 的 Windows 服务.我所做的是通过添加以下几行来覆盖 onStart() 方法:

I need to create a windows service that when launced open a specific URL. What I did is to override the onStart() method by adding the following lines :

保护覆盖 void OnStart(string[] args)

protected override void OnStart(string[] args)

    {
        eventLog1.WriteEntry("Browser must start " + DateTime.Now);
        string targetURL = "http://www.mysite.com";
        System.Diagnostics.Process.Start(targetURL);
    }

然而这东西行不通.:((事情是它确实写了日志 .than 意味着 onStart 任何人都有任何想法????

However this thing doesn`t work . :(( Thing is that it does write the log .than means that onStart Anybody has any ideas????

推荐答案

服务通常在没有用户登录时启动(当它处于自动启动模式时).

The service is usually started (when it's in Automatic startup mode) when there's no user logged in.

一般来说,服务不与用户桌面交互并在单独的会话中工作.如果您需要为每个或某些登录用户执行某些操作,您需要编写一个单独的代理应用程序,该应用程序将在用户登录时自动启动,并且您的服务将与之通信.然后代理可以启动浏览器或执行您需要的任何其他操作.

In general, services don't interact with user desktop and work in a separate session. If you need something to be performed for each or some of logged in users, you need to write a separate agent application, which will be automatically started on user login, and with which your service will communicate. Then the agent can start the browser or do whatever else you need.

这篇关于如何从 Windows 服务启动浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆