By setting up and reading the registry, we can implement our application to execute the features of Windows. Below is the code implemented:
Form1.vb
Imports
Microsoft.Win32.Registry
Public
Class
Form1
Inherits
System.Windows.Forms.form
#REGION
"WINDOWS Form Designer Generated Code"
Public
Sub
New
()
Mybase
.New ()
'
This call is required for the Windows Form Designer.
InitializeComponent ()
'
Add any initialization after INITIALIZECOMPONENT () call
End Sub
'
Form rewriting disposal to clean 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
'
Windows Form Designer
Private
Components
AS
System.componentmodel.icontainer
'
Note: The following procedure is required for the Windows Form Designer
'
You can modify this process using the Windows Form Designer.
'
Do not modify it using the code editor.
Friend
Withevents
Checkbox1
AS
System.windows.Forms.checkbox
Friend
Withevents
Btnsave
AS
System.Windows.Forms.Button
<
System.Diagnostics.debuggerstepthrough ()
>
Private
Sub
InitializeComponent ()
ME
.Checkbox1
=
New
System.windows.Forms.checkbox ()
ME
.btnsave
=
New
System.windows.Forms.Button ()
ME
.Suspendlayout ()
'' '
Checkbox1
'
ME
.Checkbox1.backcolor
=
System.drawing.systemcolors.Control
ME
.Checkbox1.checked
=
True
ME
.Checkbox1.checkstate
=
System.windows.forms.checkstate.checked
ME
.Checkbox1.forecolor
=
System.drawing.systemcolors.ControlText
ME
.Checkbox1.imemode
=
System.windows.Forms.imemode.noControl
ME
.Checkbox1.name
=
"
Checkbox1
"
ME
.Checkbox1.righttoleft
=
System.windows.forms.righttoleft.yes
ME
.Checkbox1.size
=
New
SYSTEM.DRAWING.SIZE
142
,
15
)
ME
.Checkbox1.tabindex
=
twenty one
ME
.Checkbox1.text =
"
Windows is running
"
ME
.Checkbox1.textalign
=
System.drawing.contentAlignment.middleright
'' '
Btnsave
'
ME
.btnsave.backcolor
=
System.drawing.systemcolors.Control
ME
.btnsave.font
=
New
System.drawing.font
"
Song body
"
,
10.0
!)
ME
.btnsave.forecolor
=
System.drawing.systemcolors.ControlText
ME
.btnsave.imemode
=
System.windows.Forms.imemode.noControl
ME
.btnsave.location
=
New
System.drawing.point
0
,
16
)
ME
.btnsave.name
=
"
Btnsave
"
ME
.btnsave.size
=
New
SYSTEM.DRAWING.SIZE
144
,
twenty four
)
ME
.btnsave.tabindex
=
32
ME
.btnsave.text
=
"
Save Settings
"
'' '
Form1
'
ME
.Autoscalebasesize
=
New
SYSTEM.DRAWING.SIZE
5
,
13
)
ME
.ClientSize
=
New
SYSTEM.DRAWING.SIZE
144
,
40
)
ME
.Controls.addrange
New
System.windows.Forms.Control () {
ME
.btnsave,
ME
.Checkbox1})
ME
.Formorderstyle
=
System.windows.Forms.FormBorderstyle.fixedToolWindow
ME
.Name .name
=
"
Form1
"
ME
.StartPosition
=
System.windows.forms.formstartPosition.CenterScreen
ME
.Text
=
"
Windows is running
"
ME
.ResumeLayout
False
)
End Sub
#end region
DIM
REG
AS
Microsoft.Win32.RegistryKey
Private
Sub
INITVAR ()
IF
Btnsave.visible
=
True
THEN
end
IF
REG
=
CurrentUser.opensubKey
"
Software / Microsoft / Windows / CurrentVersion / Run
"
,
True
)
IF
Reg.getValue
"
Mengxianhui
"
)
<>
""
THEN
Checkbox1.checked
=
True
Else
Checkbox1.checked
=
False
End
IF
End Sub
Private
Sub
Savesettings ()
IF
Checkbox1.checked
=
True
THEN
REG
= CURRENTUSER.OPENSUBKEY
"
Software / Microsoft / Windows / CurrentVersion / Run
"
,
True
) Reg.setValue
"
Mengxianhui
"
, Application.executablePath)
Else
REG
=
CurrentUser.opensubKey
"
Software / Microsoft / Windows / CurrentVersion / Run
"
,
True
) Reg.setValue
"
Mengxianhui
"
,
""
)
End
IF
INITVAR () Messagebox.show
"
You are already set, please restart your computer.
"
,
"
prompt
"
_MessageBoxButtons.ok, MessageBoxicon.information)
IF
Checkbox1.checked
=
True
THEN
ME
.Dispose
True
)
End
IF
End Sub
Private
Sub
Btnsave_click
BYVAL
Sender
AS
System.Object,
BYVAL
e
AS
System.eventargs_
Handles
Btnsave.clicksavesettings ()
End Sub
END CLASS