Results 1 to 2 of 2

Thread: EZUpdate - Run Updates Network Wide Easily

  1. #1

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Smile EZUpdate - Run Updates Network Wide Easily

    Given your end users have certain access privileges, or ran as an administrator, this application is designed to allow you to control machines on your network using file structure.

    Simply open the host.nrf file as text and edit the location for the hosted directory.

    The application runs a designated script to launch multiple msi or what-have-you and upon completion writes back a file locally to the machine to notify that the installation has occurred. This prevents multiple installations. There is no true verification that the installs have taken place, but if you test your script you shouldn't have any issues running house-wide.

    It's a simple program, but sure beats the heck out of remoting into all your machines to run an update if you don't have any other system to distribute your fixes/installs/uninstalls.

    The code also demonstrates the correct usage file filestreams as to prevent file locks when accessing the same file more than once in your application.



    Hope some of you will find it useful
    Attached Files Attached Files
    Last edited by condonethis; Jul 6th, 2012 at 09:52 PM.

  2. #2

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Re: EZUpdate - Run Updates Network Wide Easily

    Just in case you were interested, but would rather just view the code. It illustrates properly executing an application and waiting for that application to terminate and creating text files without locking them. Truly novice material, but someone might be able to use it.

    vb Code:
    1. Imports System.IO
    2. Imports System
    3. Imports System.Text
    4.  
    5. Public Class config
    6.     Dim hostdir As String = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory & "host.nrf")
    7.     Dim doupdate As String = hostdir & "doupdate.nrf"
    8.     Dim toupdate As String = hostdir & "torun.nrf"
    9.     Dim tocheck As String = hostdir & "tocheck.nrf"
    10.     Dim localside As String = File.ReadAllText(tocheck)
    11.     Dim names As String = "Administrator"
    12.     Dim myname As String = Environment.UserName.ToString
    13.  
    14.     Public Function writetxt(ByVal tfile As String, ByVal tstr As String) As Boolean
    15.         Dim fs As FileStream = File.Create(tfile)
    16.         Dim info As Byte() = New UTF8Encoding(True).GetBytes(tstr)
    17.         fs.Write(info, 0, info.Length)
    18.         fs.Close()
    19.     End Function
    20.  
    21.     Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
    22.         Me.Hide()
    23.     End Sub
    24.  
    25.     Private Sub config_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    26.         If Directory.Exists(hostdir) = True Then
    27.         Else
    28.             MsgBox("Host Directory Unreachable")
    29.             Me.Hide()
    30.         End If
    31.         If File.Exists(doupdate) = True Then
    32.             Me.Text = "EZUpdate - Status: Active"
    33.         Else
    34.             Me.Text = "EZUpdate - Status: Disabled"
    35.         End If
    36.         If names.Contains(myname) = False Then
    37.             Me.Hide()
    38.             Me.Opacity = 0
    39.         Else
    40.             Me.TopMost = True
    41.             TxtInstallAddress.Text = File.ReadAllText(toupdate)
    42.             TxtCheckFile.Text = File.ReadAllText(tocheck)
    43.         End If
    44.     End Sub
    45.  
    46.     Private Sub BtnActivate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnActivate.Click
    47.         If File.Exists(doupdate) = False Then
    48.             Dim fs As FileStream = File.Create(doupdate)
    49.             Dim info As Byte() = New UTF8Encoding(True).GetBytes("doupdate")
    50.             fs.Write(info, 0, info.Length)
    51.             fs.Close()
    52.         End If
    53.         Me.Text = "EZUpdate - Status: Active"
    54.     End Sub
    55.  
    56.     Private Sub BtnDisable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDisable.Click
    57.         If File.Exists(doupdate) = True Then
    58.             Do Until File.Exists(doupdate) = False
    59.                 Try
    60.                     File.Delete(doupdate)
    61.                 Catch
    62.                 End Try
    63.             Loop
    64.         End If
    65.         Me.Text = "EZUpdate - Status: Disabled"
    66.     End Sub
    67.  
    68.     Public Sub writeupdate()
    69.         Dim updstrchk As String = TxtCheckFile.Text
    70.         Dim updstrrun As String = TxtInstallAddress.Text
    71.  
    72.  
    73.         If updstrchk <> "" And updstrrun <> "" Then
    74.             If File.Exists(updstrrun) = True Then
    75.                 'Write update location
    76.                 If File.Exists(toupdate) = True Then
    77.                     Do Until File.Exists(toupdate) = False
    78.                         Try
    79.                             File.Delete(toupdate)
    80.                         Catch
    81.                         End Try
    82.                     Loop
    83.                 End If
    84.                 Try
    85.                     writetxt(toupdate, updstrrun)
    86.                 Catch ex As Exception
    87.                     MsgBox(ex.Message)
    88.                 End Try
    89.  
    90.                 'Write file to check
    91.  
    92.                 If File.Exists(tocheck) = True Then
    93.                     Do Until File.Exists(tocheck) = False
    94.                         Try
    95.                             File.Delete(tocheck)
    96.                         Catch
    97.                         End Try
    98.                     Loop
    99.                 End If
    100.                 Try
    101.                     writetxt(tocheck, updstrchk)
    102.                 Catch ex As Exception
    103.                     MsgBox(ex.Message)
    104.                 End Try
    105.  
    106.             Else
    107.                 MsgBox("Cannot find the update script")
    108.             End If
    109.         Else
    110.             MsgBox("Must be configured.", MsgBoxStyle.Information, "Missing Configuration")
    111.         End If
    112.     End Sub
    113.  
    114.     Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
    115.         If names.Contains(myname) = True Then
    116.             Me.Show()
    117.         End If
    118.     End Sub
    119.  
    120.     Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click
    121.         writeupdate()
    122.     End Sub
    123.  
    124.     Private Sub TmrCheck_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TmrCheck.Tick
    125.         If Directory.Exists(hostdir) = True Then
    126.             'Reaccess files
    127.             doupdate = hostdir & "doupdate.nrf"
    128.             toupdate = hostdir & "torun.nrf"
    129.             tocheck = hostdir & "tocheck.nrf"
    130.             localside = File.ReadAllText(tocheck)
    131.  
    132.             'Check for Update
    133.             If File.Exists(doupdate) = True Then
    134.                 If File.Exists(localside) = False Then
    135.                     TmrCheck.Enabled = False
    136.                     donttouch.Show()
    137.                     Dim objproc As System.Diagnostics.Process
    138.                     objproc = New System.Diagnostics.Process()
    139.                     objproc.StartInfo.FileName = toupdate
    140.                     objproc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    141.                     objproc.Start()
    142.                     objproc.WaitForExit()
    143.                     objproc.Close()
    144.                     writetxt(localside, "done")
    145.                     donttouch.Hide()
    146.                     TmrCheck.Enabled = True
    147.                 End If
    148.             End If
    149.         End If
    150.     End Sub
    151. End Class

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width