//Check for registry keys
RegistryKey rkToS = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\TcpIp\\Parameters", true);
// If the return value is null, the key doesn't exist
if (rkToS == null)
{
// The key doesn't exist; create it
rkToS = Registry.LocalMachine.CreateSubKey("SYSTEM\\CurrentControlSet\\Services\\TcpIp\\Parameters");
}
// Attempt to retrieve the value for DisableUserTOSSetting; if null returned, the value doesn't exist in the registry.
if (rkToS.GetValue("DisableUserTOSSetting") != null)
{
// The value exists;
int checkToSKey = (int)rkToS.GetValue("DisableUserTOSSetting");
//Check if it has the right value
if (checkToSKey != 0)
{
//Wrong value...correcting it
rkToS.SetValue("DisableUserTOSSetting", 0);
MessageBox.Show("I have just changed the Registry Key to enable ToS values.\nFor this to take effect, you need to restart your computer!");
return;
}
}
else
{
//add value
rkToS.SetValue("DisableUserTOSSetting", 0);
MessageBox.Show("I have just added the Registry Key to enable ToS values.\nFor this to take effect, you need to restart your computer!");
return;
}
Auto enable ToS/DSCP setting in the Registry in C#
16 04 2009Comments : Leave a Comment »
Tags: C#, DisableUserTOSSetting, DSCP, regedit, Registry Key, TCPIP, ToS
Categories : C#, Networking, Random Code
How to download a file from a URL and save onto local directory in C#
12 04 2009using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/aaa.txt");
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream s = resp.GetResponseStream();
byte[] buf = new byte[16384];
using (FileStream fs = new FileStream(@"C:\bbb.txt", FileMode.Create, FileAccess.Write))
{
for (; ; )
{
int len = s.Read(buf, 0, buf.Length);
if (len == 0) break;
fs.Write(buf, 0, len);
}
}
s.Close();
}
}
}
Comments : Leave a Comment »
Tags: C#
Categories : C#, Random Code