Advertisement
lenhq

VB.Net Updater TuT *Program Part*

Jan 11th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4.  
  5.  
  6.     'These Subs are used in the program that the Updater will be Updating
  7.  
  8.  
  9.  
  10.  
  11.     Public Shared MyVersion As String = 1 'The version of the program, Used to detect either to update or not in the Updater exe
  12.    Public Shared Dir As String = Directory.GetCurrentDirectory() 'Variable storing the current directory
  13.  
  14.     Sub UpdateMe()
  15.         'Button to close program and launch the updater
  16.        Application.DoEvents()
  17.         Label1.Text = "opening updater"
  18.         MessageBox.Show("This program will now close and launch the Updater")
  19.         Process.Start(Dir + "\Update.exe")
  20.         Me.Close()
  21.     End Sub
  22.     Public Sub VersionTextFile()
  23.         'Checks if the program needs to Create Version.txt
  24.        'or if it already exists and it can continue to
  25.        'write the version number to the text file
  26.        Application.DoEvents()
  27.         Dim FILE_NAME As String = Dir + "\Version.txt"
  28.         If System.IO.File.Exists(FILE_NAME) = True Then
  29.             Label1.Text = "txt file exists"
  30.             Application.DoEvents()
  31.             Label1.Text = "Carry on sir"
  32.             WriteVersionText()
  33.         Else
  34.             Application.DoEvents()
  35.             Label1.Text = "no txt file there"
  36.             File.Create(FILE_NAME).Dispose()
  37.             Label1.Text = "now there is"
  38.             WriteVersionText()
  39.         End If
  40.     End Sub
  41.     Public Sub AdminCheck()
  42.         'I include this in my program for 2 reasons, some
  43.        'of the Functions it has require admin and so
  44.        'no matter where the program is located it will
  45.        'still be able to write the text file
  46.        Application.DoEvents()
  47.         If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
  48.             Label1.Text = "Admin Check Finished"
  49.         Else
  50.             MsgBox("Must Run Program As Admin To Run Properly")
  51.             Me.Close()
  52.         End If
  53.     End Sub
  54.     Public Sub WriteVersionText()
  55.         'This simply writes the version number to the text file
  56.        Application.DoEvents()
  57.         Label1.Text = "Writing Version"
  58.         Dim objReader As StreamWriter
  59.         objReader = New StreamWriter(Dir + "\Version.txt")
  60.         objReader.Write(MyVersion)
  61.         objReader.Close()
  62.     End Sub
  63.  
  64.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  65.         AdminCheck()
  66.         VersionTextFile()
  67.     End Sub
  68.  
  69.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  70.  
  71.     End Sub
  72. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement