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
Alte URL:
/snippet/autostart-with-windows-property/786
SUPER SACHE!
Mit folgender Modifikation, kann man das Programm Benutzerunabhängig starten: [code]
Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
„SOFTWAREMicrosoftWindowsCurrentVersionRun“, True)
[/code]
Generell ganz gut, aber unmanaged Code per Dll-Import. Das geht besser über die managed Klassen aus dem Namespace Microsoft.Win32.Registry.
siehe http://msdn2.microsoft.com/en-us/library/microsoft.win32.registry.aspx