首页 > 编程 > .NET > 正文

VB.NET轻松操作注册表

2024-07-10 13:01:00
字体:
来源:转载
供稿:网友


收集最实用的网页特效代码!

在.net中操作注册表, 和vs studio 时代,真是不可同日而语, .net 之前的操作, 要引入大量的 api 函数,含有键值类型, 错误类型等, 繁琐的要死, 而.net中,实现起来的简单程度,已经和 delphi 基本相同了,下面通过例子体验一下:



代码:
------------------------------------------------------------------------------------
imports microsoft.win32.registry
public class frmmain
inherits system.windows.forms.form

private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click
me.dispose(true)
end sub

private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
dim reg as microsoft.win32.registrykey
reg = currentuser.opensubkey("software/microsoft/windows/currentversion/run", true)
if reg.getvalue("test") <> "" then
msgbox("改键值已经存在", msgboxstyle.information, "提示")
else
reg.setvalue("test", txtkeyvalue.text)
msgbox("设置成功!", msgboxstyle.information, "提示")
end if
reg.close()
reg = nothing
end sub

private sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.click
dim reg as microsoft.win32.registrykey
reg = currentuser.opensubkey("software/microsoft/windows/currentversion/run", true)
if reg.getvalue("test") <> "" then
reg.deletevalue("test")
msgbox("已删除")
else
msgbox("不存在")
end if
reg.close()
reg = nothing
end sub

private sub chkautostart_checkedchanged(byval sender as system.object, byval e as system.eventargs) handles chkautostart.checkedchanged
dim regkey as microsoft.win32.registrykey
regkey = currentuser.opensubkey("software/microsoft/windows/currentversion/run", true)
if chkautostart.checked then
if regkey.getvalue("sjcatsoft") = "" then
regkey.setvalue("sjcatsoft", application.executablepath)
end if
else
if regkey.getvalue("sjcatsoft") <> "" then
regkey.deletevalue("sjcatsoft")
end if
end if
regkey.close()
regkey = nothing
end sub
end class


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表