笔记10
这里要用到的ShowBootIni.exe程序集的代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ShowBootIni
{
class Program
{
static void Main(string[] args)
{
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(Environment.ExpandEnvironmentVariables("%systemdrive%") + @"\boot.ini"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
sr.Close();
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ShowBootIni
{
class Program
{
static void Main(string[] args)
{
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(Environment.ExpandEnvironmentVariables("%systemdrive%") + @"\boot.ini"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
sr.Close();
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace AppDomainDemo
{
class Program
{
static void Main(string[] args)
{
// Create an AppDomain.
AppDomain d = AppDomain.CreateDomain("New Domain");
// Run the assembly
// TODO: Edit the path to the executable file
d.ExecuteAssembly("ShowBootIni.exe");
}
}
}
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace AppDomainDemo
{
class Program
{
static void Main(string[] args)
{
// Create an AppDomain.
AppDomain d = AppDomain.CreateDomain("New Domain");
// Run the assembly
// TODO: Edit the path to the executable file
d.ExecuteAssembly("ShowBootIni.exe");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AppDomainDemo
{
class Program
{
static void Main(string[] args)
{
// Create an AppDomain.
AppDomain d = AppDomain.CreateDomain("New Domain");
// Run the assembly
// TODO: Edit the path to the executable file
d.ExecuteAssemblyByName("ShowBootIni");
}
}
}
using System.Collections.Generic;
using System.Text;
namespace AppDomainDemo
{
class Program
{
static void Main(string[] args)
{
// Create an AppDomain.
AppDomain d = AppDomain.CreateDomain("New Domain");
// Run the assembly
// TODO: Edit the path to the executable file
d.ExecuteAssemblyByName("ShowBootIni");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Security;
using System.Security.Policy;
namespace AppDomainDemo
{
class Program
{
static void Main(string[] args)
{
try
{
// Create an Evidence object for the Internet zone
Zone safeZone = new Zone(SecurityZone.Internet);
object[] hostEvidence = { new Zone(SecurityZone.Internet) };
Evidence e = new Evidence(hostEvidence, null);
// Create an AppDomain.
AppDomain d = AppDomain.CreateDomain("New Domain", e);
// Run the assembly
d.ExecuteAssemblyByName("ShowBootIni");
}
catch (Exception ex)
{
Console.WriteLine("{0} {1}", ex.Source, ex.Message);
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Security;
using System.Security.Policy;
namespace AppDomainDemo
{
class Program
{
static void Main(string[] args)
{
try
{
// Create an Evidence object for the Internet zone
Zone safeZone = new Zone(SecurityZone.Internet);
object[] hostEvidence = { new Zone(SecurityZone.Internet) };
Evidence e = new Evidence(hostEvidence, null);
// Create an AppDomain.
AppDomain d = AppDomain.CreateDomain("New Domain", e);
// Run the assembly
d.ExecuteAssemblyByName("ShowBootIni");
}
catch (Exception ex)
{
Console.WriteLine("{0} {1}", ex.Source, ex.Message);
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.Net;
using System.IO;
namespace MonitorWebSite
{
public partial class MonitorWebSite : ServiceBase
{
private Timer t = null;
public MonitorWebSite()
{
InitializeComponent();
t = new Timer(10000);
t.Elapsed += new ElapsedEventHandler(t_Elapsed);
}
void t_Elapsed(object sender, ElapsedEventArgs e)
{
try
{
// Send the HTTP request
string url = "http://www.microsoft.com";
HttpWebRequest g = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse r = (HttpWebResponse)g.GetResponse();
// Log the response to a text file
string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log.txt";
TextWriter tw = new StreamWriter(path, true);
tw.WriteLine(DateTime.Now.ToString() + " for " + url + ": " + r.StatusCode.ToString());
tw.Close();
// Close the HTTP response
r.Close();
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("Application", "Exception: " + ex.Message.ToString());
}
}
protected override void OnStart(string[] args)
{
t.Start();
}
protected override void OnStop()
{
t.Stop();
}
protected override void OnContinue()
{
t.Start();
}
protected override void OnPause()
{
t.Stop();
}
protected override void OnShutdown()
{
t.Stop();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.Net;
using System.IO;
namespace MonitorWebSite
{
public partial class MonitorWebSite : ServiceBase
{
private Timer t = null;
public MonitorWebSite()
{
InitializeComponent();
t = new Timer(10000);
t.Elapsed += new ElapsedEventHandler(t_Elapsed);
}
void t_Elapsed(object sender, ElapsedEventArgs e)
{
try
{
// Send the HTTP request
string url = "http://www.microsoft.com";
HttpWebRequest g = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse r = (HttpWebResponse)g.GetResponse();
// Log the response to a text file
string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log.txt";
TextWriter tw = new StreamWriter(path, true);
tw.WriteLine(DateTime.Now.ToString() + " for " + url + ": " + r.StatusCode.ToString());
tw.Close();
// Close the HTTP response
r.Close();
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("Application", "Exception: " + ex.Message.ToString());
}
}
protected override void OnStart(string[] args)
{
t.Start();
}
protected override void OnStop()
{
t.Stop();
}
protected override void OnContinue()
{
t.Start();
}
protected override void OnPause()
{
t.Stop();
}
protected override void OnShutdown()
{
t.Stop();
}
}
}

浙公网安备 33010602011771号