Since the question mentions an .exe file, I assume you're on Windows. If so, you can do this with PowerShell.
The script
# Set some variables to hold the source, name and destination of the update file $UpdateUrl = "http://example.com/" $UpdateFile = "update.zip" $Destination = "C:\Path\to\application\" $TempDir = $Env:Temp + "\" # Download the update file to a temporary directory $Client = New-Object System.Net.WebClient $Client.DownloadFile($UpdateUrl + $UpdateFile, $TempDir + $UpdateFile) # Calculate MD5 hash of the downloaded update file $MD5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider $Hash1 = [System.BitConverter]::ToString( $MD5.ComputeHash([System.IO.File]::ReadAllBytes($TempDir + $UpdateFile)) ) # If an old update file exists at the destination, calculate its MD5 hash as well If (Test-Path ($Destination + $UpdateFile)) { $Hash2 = [System.BitConverter]::ToString( $MD5.ComputeHash([System.IO.File]::ReadAllBytes($Destination + $UpdateFile)) ) } Else { $Hash2 = "" } # Compare the MD5 hashes # If they're not equal, then copy the new update file to the destination and extract its contents If ($Hash1 -ne $Hash2) { Copy-Item ($TempDir + $UpdateFile) $Destination $Shell = New-Object -ComObject Shell.Application $Shell.NameSpace($Destination).CopyHere( $Shell.NameSpace($Destination + $UpdateFile).Items(), 20 ) } # Delete the downloaded update file Remove-Item ($TempDir + $UpdateFile)
Explanation
The first block declares some variables that contain the name, source and destination of the update file, as well as a temporary directory to hold the downloaded update file. Don't forget the trailing slashes when you change them to your own paths.
The next block uses the WebClient object to download the file to the temporary directory.
Next, the script calculates the MD5 hash of the downloaded file. If you want to calculate a different hash, like SHA-1, check out the available classes in the System.Security.Cryptography namespace.
Then, the script checks for the existence of an old update file at the destination folder, and calculates its MD5 hash.
Next, the two hashes are compared. If they're not equal, it means there has been an update. The script then uses the Windows Shell object to copy the update file to the destination folder and extract its contents. The number 20 is the sum of two options of the CopyHere() function - 4 (which supresses the progress dialog) and 16 (which answers "Yes to All" to any dialogs, thus automatically overwriting existing files).
Finally, the last line deletes the downloaded update file from the temp directory.
References
For more information on the classes, methods and cmdlets used, see the following links: