Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
  [VB.Net] Add to Startup and Remove from Startup
#1
vb.net 
Code:
Add Key Function:
Public Shared Sub AddReg(ByVal name As String, ByVal path As String)
  Dim Reg As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser
  Dim K As Microsoft.Win32.RegistryKey = Reg.OpenSubKey("software\microsoft\windows\currentversion\run", True)
  K.SetValue(name, path, Microsoft.Win32.RegistryValueKind.String)
End Sub


Remove Key Function:
Public Shared Sub RemoveReg(ByVal name As String)
  Dim Reg As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser
  Dim K As Microsoft.Win32.RegistryKey = Reg.OpenSubKey("software\microsoft\windows\currentversion\run", True)
  K.DeleteValue(name)
End Sub


Example Usage:
If CheckBox1.Checked = True Then
    AddReg(Me.Text, Application.ExecutablePath)
    MsgBox("Application WILL now show on startup", MsgBoxStyle.Information, "Added")
  Else
    RemoveReg(Me.Text)
    MsgBox("Application will NOT show on startup", MsgBoxStyle.Information, "Removed")
End If
Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste
www.D3n1s.Net