欢迎来到天天文库
浏览记录
ID:38722832
大小:67.00 KB
页数:5页
时间:2019-06-18
《修改注册表随机启动》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、为了用户使用方便,这不尝试增加记住用户名密码的功能,并且可以设置开机自动启动软件,一切都是为了减少用户的点击操作。可以有多种方式来保存用户信息,比如存成本地文件、xml、注册表、更有甚者存入数据库。个人认为存到数据库里这个操作在没登陆前就发生有些不太好,先去数据库取密码回来放到输入框里等着点击感觉不太好。最后采用了注册表的方式来保存这些信息。这里为了演示没有对保存进注册表的密码进行加密,为了安全应该继续对保存的密码加密。[csharp]viewplaincopyprint?1privatevoidckbKeepInfo_Chec
2、kStateChanged(objectsender,EventArgse)2{3RegistryKeylocation=Registry.LocalMachine;4RegistryKeysoft=location.OpenSubKey("SOFTWARE",true);//可写5RegistryKeymyPass=soft.CreateSubKey("FTLiang");6myPass.SetValue("s1",tbUserName.Text);7myPass.SetValue("s2",tbPassword.Text);
3、8myPass.SetValue("s3",ckbKeepInfo.Checked);9}privatevoidckbKeepInfo_CheckStateChanged(objectsender,EventArgse){RegistryKeylocation=Registry.LocalMachine;RegistryKeysoft=location.OpenSubKey("SOFTWARE",true);//可写RegistryKeymyPass=soft.CreateSubKey("FTLiang");myPass.Set
4、Value("s1",tbUserName.Text);myPass.SetValue("s2",tbPassword.Text);myPass.SetValue("s3",ckbKeepInfo.Checked);}自动登陆:[csharp]viewplaincopyprint?10privatevoidckbAutoStart_CheckStateChanged(objectsender,EventArgse)11{12if(ifFistIn==false)13{14RegistryKeylocation=Registry.
5、LocalMachine;15RegistryKeysoft=location.OpenSubKey("SOFTWARE",true);//可写16RegistryKeymyPass=soft.CreateSubKey("FTLiang");17myPass.SetValue("s4",ckbAutoStart.Checked);12if(ckbAutoStart.Checked)3{4stringexeDir=Application.ExecutablePath;//要启动的程序绝对路径5RegistryKeyrk=Regis
6、try.LocalMachine;6RegistryKeysoftWare=rk.OpenSubKey("SOFTWARE");7RegistryKeymicrosoft=softWare.OpenSubKey("Microsoft");8RegistryKeywindows=microsoft.OpenSubKey("Windows");9RegistryKeycurrent=windows.OpenSubKey("CurrentVersion");10RegistryKeyrun=current.OpenSubKey(@"R
7、un",true);//这里必须加true就是得到写入权限11run.SetValue("FTStart",exeDir);12}13else14{15stringexeDir=Application.ExecutablePath;//要启动的程序绝对路径16RegistryKeyrk=Registry.LocalMachine;17RegistryKeysoftWare=rk.OpenSubKey("SOFTWARE");18RegistryKeymicrosoft=softWare.OpenSubKey("Microsoft
8、");19RegistryKeywindows=microsoft.OpenSubKey("Windows");20RegistryKeycurrent=windows.OpenSubKey("CurrentVersion");21RegistryKeyrun=
此文档下载收益归作者所有