Imports System Imports System.Drawing Imports System.Windows.Forms Imports Microsoft.Win32 Namespace DefaultNamespace
Public Class MainForm Inherits Form Private btn As Button Private tb As TextBox
Public Sub New() InitializeComponent End Sub
<STAThread()> _ Public Shared Sub Main(ByVal args As String()) Application.Run(New MainForm) End Sub
Private Sub InitializeComponent() tb = New TextBox btn = New Button SuspendLayout tb.Location = New Point(50, 50) tb.Size = New Size(400, 200) tb.Multiline = True tb.Text = "" btn.Location = New Point(50, 300) btn.Size = New Size(400, 50) btn.Text = "Hent" AddHandler btn.Click, AddressOf ButtonClick ClientSize = New System.Drawing.Size(500, 400) Controls.Add(btn) Controls.Add(tb) Name = "Main Form" ResumeLayout(False) End Sub
Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) Dim dir As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("ASP.NET").OpenSubKey("1.1.4322.0") Dim vals As String() = dir.GetValueNames For Each v As String In vals Dim data As String = CType(dir.GetValue(v), String) tb.Text += (v & "=" & data & Microsoft.VisualBasic.Chr(13) & Microsoft.VisualBasic.Chr(10)) Next End Sub End Class End Namespace
Imports System Imports System.Drawing Imports System.Windows.Forms Imports Microsoft.Win32
Namespace DefaultNamespace Public Class MainForm Inherits Form Private btn As Button Private tb As TextBox
Public Sub New() InitializeComponent End Sub
<STAThread()> _ Public Shared Sub Main(ByVal args As String()) Application.Run(New MainForm) End Sub
Private Sub InitializeComponent() tb = New TextBox btn = New Button SuspendLayout tb.Location = New Point(50, 50) tb.Size = New Size(400, 200) tb.Multiline = True tb.Text = "" btn.Location = New Point(50, 300) btn.Size = New Size(400, 50) btn.Text = "Hent" AddHandler btn.Click, AddressOf ButtonClick ClientSize = New System.Drawing.Size(500, 400) Controls.Add(btn) Controls.Add(tb) Name = "Main Form" ResumeLayout(False) End Sub
Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) Dim dir As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("ASP.NET").OpenSubKey("1.1.4322.0") Dim vals As String() = dir.GetValueNames For Each v As String In vals Dim data As String = CType(dir.GetValue(v), String) tb.Text += (v & "=" & data & Convert.ToChar(13) & Convert.ToChar(10)) Next End Sub End Class End Namespace
Du starter med at have dette import statement Imports Microsoft.Win32
Så bruger du denne metode til at hente ud fra reg.
Public Function RegValue(ByVal Hive As RegistryHive, _ ByVal Key As String, ByVal ValueName As String, _ OptionalByRef ErrInfo As String = "") As String
Dim objParent As RegistryKey Dim objSubkey As RegistryKey Dim sAns As String Select Case Hive Case RegistryHive.ClassesRoot objParent = Registry.ClassesRoot Case RegistryHive.CurrentConfig objParent = Registry.CurrentConfig Case RegistryHive.CurrentUser objParent = Registry.CurrentUser Case RegistryHive.DynData objParent = Registry.DynData Case RegistryHive.LocalMachine objParent = Registry.LocalMachine Case RegistryHive.PerformanceData objParent = Registry.PerformanceData Case RegistryHive.Users objParent = Registry.Users
End Select
Try objSubkey = objParent.OpenSubKey(Key) 'if can't be found, object is not initialized If Not objSubkey Is Nothing Then sAns = (objSubkey.GetValue(ValueName)) End If
Catch ex As Exception
ErrInfo = ex.Message Finally
'if no error but value is empty, populate errinfo If ErrInfo = "" And sAns = "" Then ErrInfo = _ "No value found for requested registry key" End If End Try Return sAns End Function
Nu kan du så sige: Textbox1.Text = RegValue(RegistryHive.LocalMachine,"SOFTWARE\Microsoft\Windows\CurrentVersion","ProgramFilesDir", sErr)
'This call is required by the Windows Form Designer. InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub
'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor.
Friend WithEvents smtptb As System.Windows.Forms.TextBox Friend WithEvents lukbt As System.Windows.Forms.Button Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents afsender As System.Windows.Forms.TextBox Friend WithEvents modtager As System.Windows.Forms.TextBox Friend WithEvents subjekt As System.Windows.Forms.TextBox Friend WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents sti As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.smtptb = New System.Windows.Forms.TextBox Me.lukbt = New System.Windows.Forms.Button Me.afsender = New System.Windows.Forms.TextBox Me.modtager = New System.Windows.Forms.TextBox Me.subjekt = New System.Windows.Forms.TextBox Me.Label1 = New System.Windows.Forms.Label Me.Button1 = New System.Windows.Forms.Button Me.Label2 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.Label4 = New System.Windows.Forms.Label Me.Label6 = New System.Windows.Forms.Label Me.sti = New System.Windows.Forms.TextBox Me.SuspendLayout() ' 'smtptb ' Me.smtptb.Location = New System.Drawing.Point(232, 48) Me.smtptb.Name = "smtptb" Me.smtptb.TabIndex = 1 Me.smtptb.Text = "" ' 'lukbt ' Me.lukbt.Location = New System.Drawing.Point(512, 408) Me.lukbt.Name = "lukbt" Me.lukbt.Size = New System.Drawing.Size(136, 23) Me.lukbt.TabIndex = 6 Me.lukbt.Text = "GEM OG LUK" ' 'afsender ' Me.afsender.Location = New System.Drawing.Point(232, 112) Me.afsender.Name = "afsender" Me.afsender.TabIndex = 3 Me.afsender.Text = "" ' 'modtager ' Me.modtager.Location = New System.Drawing.Point(232, 80) Me.modtager.Name = "modtager" Me.modtager.TabIndex = 2 Me.modtager.Text = "" ' 'subjekt ' Me.subjekt.Location = New System.Drawing.Point(232, 144) Me.subjekt.Name = "subjekt" Me.subjekt.TabIndex = 4 Me.subjekt.Text = "" ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(104, 56) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(96, 16) Me.Label1.TabIndex = 11 Me.Label1.Text = "SMTP Server" ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(384, 408) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 12 Me.Button1.Text = "Button1" ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(104, 152) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(96, 16) Me.Label2.TabIndex = 13 Me.Label2.Text = "Overskrift" ' 'Label3 ' Me.Label3.Location = New System.Drawing.Point(104, 120) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(96, 16) Me.Label3.TabIndex = 14 Me.Label3.Text = "Email afsender" ' 'Label4 ' Me.Label4.Location = New System.Drawing.Point(104, 88) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(96, 16) Me.Label4.TabIndex = 15 Me.Label4.Text = "Email Modtager" ' 'Label6 ' Me.Label6.Location = New System.Drawing.Point(104, 184) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(96, 16) Me.Label6.TabIndex = 17 Me.Label6.Text = "Sti til fil" ' 'sti ' Me.sti.Location = New System.Drawing.Point(232, 176) Me.sti.Name = "sti" Me.sti.TabIndex = 5 Me.sti.Text = "" ' 'confi ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(680, 478) Me.Controls.Add(Me.sti) Me.Controls.Add(Me.Label6) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.subjekt) Me.Controls.Add(Me.modtager) Me.Controls.Add(Me.afsender) Me.Controls.Add(Me.smtptb) Me.Controls.Add(Me.lukbt) Me.Name = "confi" Me.ResumeLayout(False)
End Sub
#End Region
Private Sub confi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lukbt.Click Dim sw As StreamWriter Dim regKey As RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True) regKey.CreateSubKey("lysavis")
Private Sub smtptb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles smtptb.TextChanged
End Sub
Private Sub ostb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modtager.TextChanged
End Sub
Private Sub afbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles afsender.TextChanged
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Dim regKey As RegistryKey 'regKey = Registry.LocalMachine.OpenSubKey("Software\lysavis", True) 'smtptb.Text = regKey.GetValue("smtp") End Sub
Private Sub sti_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sti.TextChanged
End Sub
Private Sub subjekt_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles subjekt.TextChanged
Hvilken metode fik du til at spille om man må spørge?
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.