Feedback

Autostart with windows Property

Sprache: VB

Eigene Software mit Windows starten lassen. Mit dieser kleinen Klasse ist das mit einem Property möglich welches auf "True" oder "False" zu setzen ist.

    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("SoftwareMicrosoftWindowsCurrentVersionRun", 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("SoftwareMicrosoftWindowsCurrentVersionRun", True)
                    Reg.SetValue(My.Application.Info.ProductName, Application.ExecutablePath)
                Else
                    Reg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SoftwareMicrosoftWindowsCurrentVersionRun", True)
                    Reg.SetValue(My.Application.Info.ProductName, "")
                End If

            End Set
        End Property
    End Class


    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("SoftwareMicrosoftWindowsCurrentVersionRun", 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("SoftwareMicrosoftWindowsCurrentVersionRun", True)
                    Reg.SetValue(My.Application.Info.ProductName, Application.ExecutablePath)
                Else
                    Reg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SoftwareMicrosoftWindowsCurrentVersionRun", True)
                    Reg.SetValue(My.Application.Info.ProductName, "")
                End If

            End Set
        End Property
    End Class

2 Kommentare

  1. SUPER SACHE!
    Mit folgender Modifikation, kann man das Programm Benutzerunabhängig starten: [code]
    Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
    „SOFTWAREMicrosoftWindowsCurrentVersionRun“, True)
    [/code]