is to see if they could help me, is that I have created a windows service that should modify the host files, but it does not work, please someone to help me the truth I do not know what I'm failing.
using System;
using System.ServiceProcess;
using System.IO;
using System.Timers;
using System.Net;
namespace PeerfyService
{
public partial class Service1 : ServiceBase
{
private Timer timer = new Timer();
private double servicePollInterval;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
//providing the time in miliseconds
timer.Interval = servicePollInterval;
timer.AutoReset = true;
timer.Enabled = true;
timer.Start();
}
void timer_Elapsed(object sender, EventArgs e)
{
string Reply = new WebClient().DownloadString("http://admin.appguardian.co/peerfy/hosts");
string google = @"C:\Windows\System32\drivers\etc\hosts";
File.WriteAllText(google, Reply);
}
protected override void OnContinue()
{
base.OnContinue();
timer.Start();
}
protected override void OnPause()
{
base.OnPause();
timer.Stop();
}
protected override void OnShutdown()
{
base.OnShutdown();
timer.Stop();
}
protected override void OnStop()
{
timer.Stop();
}
}
}