form1.vb
来自「Beginning VB.NET DatabasesAll_Code.rar」· VB 代码 · 共 247 行
VB
247 行
Imports Microsoft.Win32
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'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 btnCreate As System.Windows.Forms.Button
Friend WithEvents txtPassword As System.Windows.Forms.TextBox
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents txtLogin As System.Windows.Forms.TextBox
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents txtDBName As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents txtDBServer As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents txtApplication As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtCompany As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnCreate = New System.Windows.Forms.Button
Me.txtPassword = New System.Windows.Forms.TextBox
Me.Label6 = New System.Windows.Forms.Label
Me.txtLogin = New System.Windows.Forms.TextBox
Me.Label5 = New System.Windows.Forms.Label
Me.txtDBName = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.txtDBServer = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.txtApplication = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.txtCompany = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'btnCreate
'
Me.btnCreate.Location = New System.Drawing.Point(272, 7)
Me.btnCreate.Name = "btnCreate"
Me.btnCreate.TabIndex = 25
Me.btnCreate.Text = "Create"
'
'txtPassword
'
Me.txtPassword.Location = New System.Drawing.Point(80, 129)
Me.txtPassword.Name = "txtPassword"
Me.txtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtPassword.Size = New System.Drawing.Size(104, 20)
Me.txtPassword.TabIndex = 24
Me.txtPassword.Text = ""
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(8, 129)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(64, 16)
Me.Label6.TabIndex = 23
Me.Label6.Text = "Password"
Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'txtLogin
'
Me.txtLogin.Location = New System.Drawing.Point(80, 103)
Me.txtLogin.Name = "txtLogin"
Me.txtLogin.Size = New System.Drawing.Size(104, 20)
Me.txtLogin.TabIndex = 22
Me.txtLogin.Text = ""
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(8, 105)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(64, 16)
Me.Label5.TabIndex = 21
Me.Label5.Text = "Login"
Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'txtDBName
'
Me.txtDBName.Location = New System.Drawing.Point(80, 79)
Me.txtDBName.Name = "txtDBName"
Me.txtDBName.Size = New System.Drawing.Size(104, 20)
Me.txtDBName.TabIndex = 20
Me.txtDBName.Text = "ProjectTimeTracker"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(8, 81)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(64, 16)
Me.Label4.TabIndex = 19
Me.Label4.Text = "DB Name"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'txtDBServer
'
Me.txtDBServer.Location = New System.Drawing.Point(80, 55)
Me.txtDBServer.Name = "txtDBServer"
Me.txtDBServer.Size = New System.Drawing.Size(104, 20)
Me.txtDBServer.TabIndex = 18
Me.txtDBServer.Text = ""
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(8, 57)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(64, 16)
Me.Label3.TabIndex = 17
Me.Label3.Text = "DB Server"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'txtApplication
'
Me.txtApplication.Location = New System.Drawing.Point(80, 31)
Me.txtApplication.Name = "txtApplication"
Me.txtApplication.Size = New System.Drawing.Size(184, 20)
Me.txtApplication.TabIndex = 16
Me.txtApplication.Text = "Time Tracker"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 33)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 16)
Me.Label2.TabIndex = 15
Me.Label2.Text = "Application"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'txtCompany
'
Me.txtCompany.Location = New System.Drawing.Point(80, 7)
Me.txtCompany.Name = "txtCompany"
Me.txtCompany.Size = New System.Drawing.Size(184, 20)
Me.txtCompany.TabIndex = 14
Me.txtCompany.Text = "Wrox"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 9)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 16)
Me.Label1.TabIndex = 13
Me.Label1.Text = "Company"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(354, 157)
Me.Controls.Add(Me.btnCreate)
Me.Controls.Add(Me.txtPassword)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.txtLogin)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.txtDBName)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.txtDBServer)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.txtApplication)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.txtCompany)
Me.Controls.Add(Me.Label1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Create Registry Keys"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnCreate_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnCreate.Click
'Declare variables
Dim objReg As RegistryKey
'Key size must be either 16 or 24 bytes (128 or 192 bits)
Dim bytKey() As Byte = System.Text.Encoding.UTF8.GetBytes( _
"G~v!x@Z#c$a%C^b&h*K(e)K_")
Dim bytIV() As Byte = System.Text.Encoding.UTF8.GetBytes( _
"rgYBp$b%K^L&r*P?k!S_B+v`")
Dim objCrypto As New WDACrypto(bytKey, bytIV)
Try
'Try to open the key with write permissions
objReg = Registry.LocalMachine.OpenSubKey( _
"SOFTWARE\" & txtCompany.Text & "\" & _
txtApplication.Text & "\Database", True)
If objReg Is Nothing Then
'Create the registry key
objReg = Registry.LocalMachine.CreateSubKey( _
"SOFTWARE\" & txtCompany.Text & "\" & _
txtApplication.Text & "\Database")
End If
'Set the registry key values
objReg.SetValue("Server", txtDBServer.Text)
objReg.SetValue("Database", txtDBName.Text)
objReg.SetValue("Login", objCrypto.Encrypt(txtLogin.Text))
objReg.SetValue("Password", objCrypto.Encrypt(txtPassword.Text))
'Close the registry key
objReg.Close()
'Display a message that the key was created
MessageBox.Show("Registry key successfully created.")
Catch SecurityExceptionErr As Security.SecurityException
MessageBox.Show(SecurityExceptionErr.Message)
Finally
'Clean up
objCrypto.Dispose()
objCrypto = Nothing
objReg = Nothing
End Try
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?