Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Public Class Form1
- 'These Subs are used in the program that the Updater will be Updating
- Public Shared MyVersion As String = 1 'The version of the program, Used to detect either to update or not in the Updater exe
- Public Shared Dir As String = Directory.GetCurrentDirectory() 'Variable storing the current directory
- Sub UpdateMe()
- 'Button to close program and launch the updater
- Application.DoEvents()
- Label1.Text = "opening updater"
- MessageBox.Show("This program will now close and launch the Updater")
- Process.Start(Dir + "\Update.exe")
- Me.Close()
- End Sub
- Public Sub VersionTextFile()
- 'Checks if the program needs to Create Version.txt
- 'or if it already exists and it can continue to
- 'write the version number to the text file
- Application.DoEvents()
- Dim FILE_NAME As String = Dir + "\Version.txt"
- If System.IO.File.Exists(FILE_NAME) = True Then
- Label1.Text = "txt file exists"
- Application.DoEvents()
- Label1.Text = "Carry on sir"
- WriteVersionText()
- Else
- Application.DoEvents()
- Label1.Text = "no txt file there"
- File.Create(FILE_NAME).Dispose()
- Label1.Text = "now there is"
- WriteVersionText()
- End If
- End Sub
- Public Sub AdminCheck()
- 'I include this in my program for 2 reasons, some
- 'of the Functions it has require admin and so
- 'no matter where the program is located it will
- 'still be able to write the text file
- Application.DoEvents()
- If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
- Label1.Text = "Admin Check Finished"
- Else
- MsgBox("Must Run Program As Admin To Run Properly")
- Me.Close()
- End If
- End Sub
- Public Sub WriteVersionText()
- 'This simply writes the version number to the text file
- Application.DoEvents()
- Label1.Text = "Writing Version"
- Dim objReader As StreamWriter
- objReader = New StreamWriter(Dir + "\Version.txt")
- objReader.Write(MyVersion)
- objReader.Close()
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- AdminCheck()
- VersionTextFile()
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement