我需要構建一個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