新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Command1_Click()
Call f_SaveReg("Hello")
Debug.Print f_ReadReg
End Sub
Private Function f_ReadReg() As String
Dim w As Object
On Error Resume Next
Set w = CreateObject("wscript.shell")
f_ReadReg = w.regread("HKEY_CURRENT_USER\SOFTWARE\VB and VBA Program Settings\test")
Exit Function
End Function
Private Function f_SaveReg(ByVal strContent As String) As String
Set wsh = CreateObject("Wscript.Shell")
wsh.RegWrite "HKEY_CURRENT_USER\SOFTWARE\VB and VBA Program Settings\test", strContent
End Function
运行结果:
Hello
打开注册表:
计算机\HKEY_CURRENT_USER\SOFTWARE\VB and VBA Program Settings
也可以看到,记得按Del键删除。