我需要构建一个Windows服务来监视网络(IP)并相应地修改代理设置。Windows服务观看网络
服务将被安装,并且应该监视IP以检测它是内部还是外部IP。
我已经基于互联网上的指南创建了一个基本的Windows服务,但我不确定什么是从这里开始的最佳途径。
从指南我注意到,WindowsService
对象有某种事件系统,我想知道是否有可能挂钩?
这是基本的代码。
using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.ComponentModel;
using System.Configuration.Install;
namespace WindowsService
{
[RunInstaller(true)]
public class WindowsServiceInstaller : Installer
{
public WindowsServiceInstaller()
{
ServiceProcessInstaller SPI = new ServiceProcessInstaller();
ServiceInstaller SI = new ServiceInstaller();
//# Service Account Information
SPI.Account = ServiceAccount.LocalSystem;
SPI.Username = null;
SPI.Password = null;
//# Service Information
SI.DisplayName = WindowsService._WindowsServiceName;
SI.StartType = ServiceStartMode.Automatic;
//# set in the constructor of WindowsService.cs
SI.ServiceName = WindowsService._WindowsServiceName;
Installers.Add(SPI);
Installers.Add(SI);
}
}
class WindowsService : ServiceBase
{
public static string _WindowsServiceName = "Serco External Proxy Manager";
public WindowsService()
{
ServiceName = _WindowsServiceName;
EventLog.Log = "Application";
// These Flags set whether or not to handle that specific
// type of event. Set to true if you need it, false otherwise.
CanHandlePowerEvent = true;
CanHandleSessionChangeEvent = true;
CanPauseAndContinue = true;
CanShutdown = true;
CanStop = true;
}
static void Main()
{
ServiceBase.Run(new WindowsService());
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
}
protected override void OnStop()
{
base.OnStop();
}
protected override void OnPause()
{
base.OnPause();
}
protected override void OnContinue()
{
base.OnContinue();
}
}
}
任何帮助表示赞赏
我意识到这并不直接回答你的问题。但它可能有帮助...而不是创建自己的代码来更改代理设置,也许你可以使用http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol? – 2011-01-31 16:36:42
谢谢,但似乎有一定的局限性,我认为会造成问题与我们的企业网络,比如我们保持浏览器亲自到用户 – RobertPitt 2011-01-31 18:12:03