首先写一个写入注册表的文件
拷贝下面3行存为1.reg
REGEDIT4[HKEY_CURRENT_USER\Software\MyRegDataApp]
"UseTime"="10"然后在c#程序里
using Microsoft.Win32 ;private void Form1_Load(object sender, System.EventArgs e)
{
RegistryKey RootKey,RegKey; //项名为:HKEY_CURRENT_USER\Software
RootKey = Registry.CurrentUser.OpenSubKey ("Software",true);
//打开子项:HKEY_CURRENT_USER\Software\MyRegDataApp
if ((RegKey = RootKey.OpenSubKey ("MyRegDataApp",true)) == null)
{
RootKey.CreateSubKey("MyRegDataApp");//不存在,则创建子项
RegKey = RootKey.OpenSubKey ("MyRegDataApp",true);
RegKey.SetValue ("UseTime",(object)9); //创建键值,存储可使用次数
MessageBox.Show ("您可以免费使用本软件10次!","感谢您首次使用");
return;
} try
{
object usetime = RegKey.GetValue ("UseTime");//读取键值,可使用次数
MessageBox.Show ("你还可以使用本软件 :"+ usetime.ToString ()+ "次!","确认",MessageBoxButtons.OK ,MessageBoxIcon.Information );
int newtime = Int32.Parse (usetime.ToString()) -1; if (newtime<0)
{
if (MessageBox.Show ("继续使用,请购买本软件!","提示",MessageBoxButtons.OK ,MessageBoxIcon.Information )== DialogResult.OK )
{
Application.Exit ();
}
}
else
{
RegKey.SetValue ("UseTime",(object)newtime);//更新键值,可使用次数减1
}
}
catch
{
RegKey.SetValue ("UseTime",(object)10); //创建键值,存储可使用次数
MessageBox.Show ("您可以免费使用本软件10次!","感谢您首次使用");
return;
}
}
拷贝下面3行存为1.reg
REGEDIT4[HKEY_CURRENT_USER\Software\MyRegDataApp]
"UseTime"="10"然后在c#程序里
using Microsoft.Win32 ;private void Form1_Load(object sender, System.EventArgs e)
{
RegistryKey RootKey,RegKey; //项名为:HKEY_CURRENT_USER\Software
RootKey = Registry.CurrentUser.OpenSubKey ("Software",true);
//打开子项:HKEY_CURRENT_USER\Software\MyRegDataApp
if ((RegKey = RootKey.OpenSubKey ("MyRegDataApp",true)) == null)
{
RootKey.CreateSubKey("MyRegDataApp");//不存在,则创建子项
RegKey = RootKey.OpenSubKey ("MyRegDataApp",true);
RegKey.SetValue ("UseTime",(object)9); //创建键值,存储可使用次数
MessageBox.Show ("您可以免费使用本软件10次!","感谢您首次使用");
return;
} try
{
object usetime = RegKey.GetValue ("UseTime");//读取键值,可使用次数
MessageBox.Show ("你还可以使用本软件 :"+ usetime.ToString ()+ "次!","确认",MessageBoxButtons.OK ,MessageBoxIcon.Information );
int newtime = Int32.Parse (usetime.ToString()) -1; if (newtime<0)
{
if (MessageBox.Show ("继续使用,请购买本软件!","提示",MessageBoxButtons.OK ,MessageBoxIcon.Information )== DialogResult.OK )
{
Application.Exit ();
}
}
else
{
RegKey.SetValue ("UseTime",(object)newtime);//更新键值,可使用次数减1
}
}
catch
{
RegKey.SetValue ("UseTime",(object)10); //创建键值,存储可使用次数
MessageBox.Show ("您可以免费使用本软件10次!","感谢您首次使用");
return;
}
}
using System.Web;
namespace Robot
{
class Robot
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public static string index = null;
public Robot()
{
}
void PostData()
{
Stream outstream = null;
Stream instream = null;
StreamReader sr = null;
StreamReader sr1 = null;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://passport.baidu.com/?login");
HttpWebResponse response = null;
CookieContainer cookie = new CookieContainer();
request.CookieContainer = cookie;
string PostData = "username=hide708&password=1982925";
byte [] data = System.Text.Encoding.ASCII.GetBytes(PostData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
outstream = request.GetRequestStream();
outstream.Write(data,0,data.Length);
outstream.Close();
response = (HttpWebResponse)request.GetResponse();
response.Cookies = cookie.GetCookies(request.RequestUri);
instream = response.GetResponseStream();
sr = new StreamReader(instream,System.Text.Encoding.Default);
string content = null;
instream.Close();
sr.Close(); request = (HttpWebRequest)WebRequest.Create("http://post.baidu.com/f?ct=486539264&cm=58580&tn=baiduForumIndex");
request.CookieContainer = cookie;
response = (HttpWebResponse)request.GetResponse();
response.Cookies = cookie.GetCookies(request.RequestUri);
Stream str = response.GetResponseStream();
StreamReader read = new StreamReader(str,System.Text.Encoding.Default);
content = null;
str.Close();
read.Close();
request = (HttpWebRequest)WebRequest.Create("http://post.baidu.com/f?ct=&tn=&rn=&pn=&lm=&kw=x-japan&rs2=0&myselectvalue=1&word=x-japan&tb=on");
request.CookieContainer =cookie;
response = (HttpWebResponse)request.GetResponse();
response.Cookies = cookie.GetCookies(request.RequestUri);
Stream str1 = response.GetResponseStream();
read = new StreamReader(str1,System.Text.Encoding.Default);
read.Close(); while(true)
{
try
{
request = (HttpWebRequest)WebRequest.Create("http://post.baidu.com/f?kz=125660699");
request.CookieContainer = cookie;
response = (HttpWebResponse)request.GetResponse();
response.Cookies = cookie.GetCookies(request.RequestUri);
Stream strr = response.GetResponseStream();
StreamReader reader1 = new StreamReader(strr,System.Text.Encoding.Default);
Regex r = new Regex("<input type=hidden name=bs value=\"(.*)\">");
while((content = reader1.ReadLine())!=null)
{
Match m = r.Match(content);
if(m.Success)
{
index = m.Groups[1].Value.Trim();
break;
}
}
reader1.Close();
strr.Close();
request = (HttpWebRequest)WebRequest.Create("http://tiebacommit.baidu......");
request.CookieContainer = cookie;
string post = "ct=385875968&tn=baiduSubmitPost&word=x-japan&lm=63237&z=125660699&sc=4&cm=0&rn=2506148516"+"&bs="+index.Trim()+"&str2=&rs3=0&ti=回复:ProGrammer's Test&ti1=回复:ProGrammer's Test&co=顶!!";
byte [] date = System.Text.Encoding.ASCII.GetBytes(post);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = date.Length;
Stream stream1 = request.GetRequestStream();
stream1.Write(date,0,date.Length);
stream1.Close();
response = (HttpWebResponse)request.GetResponse();
response.Cookies = cookie.GetCookies(request.RequestUri);
Stream stream2 = response.GetResponseStream();
read = new StreamReader(stream2,System.Text.Encoding.Default);
while((content=read.ReadLine())!=null)
{
Console.WriteLine(content);
}
read.Close();
stream2.Close();
} catch(System.Exception e)
{
Console.WriteLine(e.Message);
}
}
}
[STAThread]
static void Main(string[] args)
{
Robot t = new Robot();
//while(true)
{
t.PostData();
//i++;
}
}
}
}
感谢你关注我的贴子,可是你给的程序我有点看不太懂,可不可以在一些部分加点注释呢?谢谢你了.
http://www.tomore.com/2/14467.html