VB - Autostart with Windows -property

By , 9/17/2012
(1 ratings)
Allow your own software to start with Windows. This small class is able to do this via a property that can be set to "True" or "False".

Author: Timo Boehme, translation by Michael List
Translate to C#
Public Class clsAutoStart
    Private Reg As Microsoft.Win32.RegistryKey
    Private m_AutoStart As Boolean

    Public Property AutoStart() As Boolean
        Get
            Dim O As Object
            Reg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
            O = Reg.GetValue(My.Application.Info.ProductName, "")
            If O Is Nothing OrElse O.ToString.Length = 0 OrElse O.ToString <> Application.ExecutablePath Then
                Return False
            Else
                Return True
            End If
        End Get
        Set(ByVal value As Boolean)
            If value = True Then
                Reg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
                Reg.SetValue(My.Application.Info.ProductName, Application.ExecutablePath)
            Else
                Reg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
                Reg.SetValue(My.Application.Info.ProductName, "")
            End If

        End Set
    End Property
End Class

Comments

 

Log in, to comment!