Module Update2 Dim F As String = "F:\Programme\AVISO\" ' WDH TERM ' Dim F As String = "\\192.168.0.91\f\Programme\AVISO\" ' VERAG ' Dim F As String = "\\192.168.0.90\f\Programme\AVISO\" 'DEVELOPER ' Dim F As String = "\\172.16.0.99\Daten\Programme\AVISO\" ' ATILLA Sub Main() 'Falls Settings existiert, wird der Pfad daraus verwendet. F = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory & "AVISOUPDATER_Settings.txt") If Not System.IO.Directory.Exists(F) Then MsgBox("ERROR_UPDATE_05: Es konnte keine Verbindung mit dem F:\ Laufwerk hergestellt werden." & vbNewLine & "Wenn Sie eine Remote-Sitzung verwenden, melden Sie sich mit dieser erneut an.", MsgBoxStyle.Critical, "ERROR") Environment.Exit(0) End If System.Console.WriteLine("3 Sekunden warten, um sicherzustellen, dass das Programm beendet wurde...") Threading.Thread.Sleep(3000) 'Falls Programm gerade am Beenden System.Console.WriteLine("Starte Update...") System.Console.WriteLine("UPDATEPFAD: " & F) ' If Not My.Computer.FileSystem.DirectoryExists(F) Then 'MsgBox("ERROR_UPDATE_02: Update-Daten existieren nicht.", MsgBoxStyle.Critical, "ERROR") ' Else Try For i As Integer = 1 To 3 Step 1 If Not DoesProcessExists("AVISO") Then If Not tryDelMain() Then MsgBox("ERROR_UPDATE_06: AVISO.exe konnte nicht gelöscht werden. Das Programm wird evtl. noch ausgeführt.", MsgBoxStyle.Critical, "ERROR") Environment.Exit(0) End If delFiles() FileCopier() If Not System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory & "AVISO.exe") Then MsgBox("ERROR_UPDATE_03: AVISO.exe konnte nicht gestartet werden.", MsgBoxStyle.Critical, "ERROR") End If If Not System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory & "upd.tmp") Then System.IO.File.Create(AppDomain.CurrentDomain.BaseDirectory & "upd.tmp") End If System.Console.WriteLine("Erfolgreich abgeschlossen...") Process.Start("AVISO.exe") Environment.Exit(0) End If Threading.Thread.Sleep(1000) Next MsgBox("ERROR_UPDATE_01: Update konnte nicht durchgeführt werden. AVISO.exe nicht beendet?", MsgBoxStyle.Critical, "ERROR") Catch ex As Exception MsgBox("ERROR_UPDATE_02: Update-Daten existieren nicht.", MsgBoxStyle.Critical, "ERROR") End Try 'End If Environment.Exit(0) End Sub Private Sub FileCopier() For Each file As String In IO.Directory.GetFiles(F) ' Ermittelt alle Dateien des Ordners IO.File.Copy(file, AppDomain.CurrentDomain.BaseDirectory & cut_file(file), True) ' Kopiert die Dateien Next Next For Each file As String In IO.Directory.GetDirectories(F) ' Ermittelt alle Unterordner des Ordners My.Computer.FileSystem.CopyDirectory(file, AppDomain.CurrentDomain.BaseDirectory & cut_file(file), True) Next End Sub Private Function cut_file(ByVal file As String) As String ' Funktion zum Entfernen der Backslashs / Ordner While file.Contains("\") file = file.Remove(0, 1) End While Return file End Function While file.Contains("\") file = file.Remove(0, 1) End While Return file End Function Private Function tryDelMain() As Boolean 'Dim f As String = "no" Try If System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory & "AVISO.exe") Then My.Computer.FileSystem.DeleteFile(AppDomain.CurrentDomain.BaseDirectory & "AVISO.exe") Return True Catch ex As Exception MsgBox("ERROR_UPDATE_04: Fehler beim Löschen: " & F & vbNewLine & ex.Message, MsgBoxStyle.Critical, "ERROR") Environment.Exit(0) Return False End Try End Function Private Sub delFiles() 'Dim f As String = "no" Try For Each file As String In IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory) ' Ermittelt alle Dateien des Ordners If Not cut_file(file).Contains("AVISOUPDATER") And Not cut_file(file).Contains("NOT_DEL_") Then ' f = file My.Computer.FileSystem.DeleteFile(file) 'Löscht das AVISO-Programm, außer den Updater ' IO.File.Delete(file) 'IO.Directory.Delete(file) End If Next Catch ex As Exception MsgBox("ERROR_UPDATE_04: Fehler beim Löschen: " & f & vbNewLine & ex.Message, MsgBoxStyle.Critical, "ERROR") Environment.Exit(0) End Try End Sub Private Function DoesProcessExists(ByVal PName As String) As Boolean For Each p As Process In System.Diagnostics.Process.GetProcessesByName(PName) If p.StartInfo.UserName = Environment.UserName Then Return True End If Next Return False End Function End Module