孟子的代码:
用VB-Script或WSH
例子:
Set regObj = CreateObject("WScript.Shell")
MsgBox("Begin to write...")
regObj.regwrite "HKCU\software\testbyshoky\","This is a test of write reg with vbscript!"
MsgBox("Write current_user\software\testbyshoky finish!")
MsgBox("Begin to read...")
Str=regObj.regread ("HKCU\software\testbyshoky\")
MsgBox(Str)
MsgBox("Begin to del...")
regObj.regdelete "HKCU\software\testbyshoky\"
___________________________________________
在ASP.NET/C#中怎么写啊,实在不好意思5555555555555555555555555555555555555
用VB-Script或WSH
例子:
Set regObj = CreateObject("WScript.Shell")
MsgBox("Begin to write...")
regObj.regwrite "HKCU\software\testbyshoky\","This is a test of write reg with vbscript!"
MsgBox("Write current_user\software\testbyshoky finish!")
MsgBox("Begin to read...")
Str=regObj.regread ("HKCU\software\testbyshoky\")
MsgBox(Str)
MsgBox("Begin to del...")
regObj.regdelete "HKCU\software\testbyshoky\"
___________________________________________
在ASP.NET/C#中怎么写啊,实在不好意思5555555555555555555555555555555555555
using Microsoft.Win32; protected void Page_Load(object sender, EventArgs e)
{
WriteRegedit("expression", "This is a test of write regedit with c#");
Response.Write(GetRegistData("expression"));
DeleteRegist();
} private string GetRegistData(string name)
{
RegistryKey aimdir = Registry.CurrentUser.OpenSubKey("SOFTWARE\\testbyshoky", true);
return aimdir.GetValue(name).ToString();
} private void WriteRegedit(string name, string tovalue)
{
RegistryKey hklm = Registry.CurrentUser;
RegistryKey software = hklm.OpenSubKey("SOFTWARE", true);
RegistryKey aimdir = software.CreateSubKey("testbyshoky");
aimdir.SetValue(name, tovalue);
} private void DeleteRegist()
{
Registry.CurrentUser.DeleteSubKey("SOFTWARE\\testbyshoky");
}
我的需求是这样的:我要用来在
void Session_Start(object sender, EventArgs e)
{}
1\记录软件使用次数,首先判断有不有某一个数值名称,如果没有数值名称就建一个,如果有数值名称判断其值是否小于50,如果小于50就加1,大于50就退出.
例如:数值名称我可以这样建吗?判断HKEY_USERS\S-1-5-18\Software\by\counter是否存在,如果不存在就创建它,如果存在就判断HKEY_USERS\S-1-5-18\Software\by\counter的值是否大于50
谢谢!
RegistryKey bydir = Registry.CurrentUser.OpenSubKey("SOFTWARE\\by", true);
int count_int = 1;
if (bydir.GetValue("counter") == null)
{
RegistryKey hklm = Registry.CurrentUser;
RegistryKey software = hklm.OpenSubKey("SOFTWARE", true);
RegistryKey aimdir = software.CreateSubKey("by");
aimdir.SetValue("counter", 1);
}
else
{
string count_str = bydir.GetValue("counter").ToString();
count_int = Int32.Parse(count_str);
count_int = count_int + 1;
}
if (count_int <= 30)
{...}
问题:行 59: if (bydir.GetValue("counter") == null)
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
RegistryKey bydir = Registry.CurrentUser.CreateSubKey("SOFTWARE\\by");