Hi guys,
Thought i'd share some code to help people getting the tool to run on windows.
The code I think is self explanatory.
- Without downloading the script...
powershell -nop -c "iex(New-Object Net.WebClient).DownloadString('https://exiftool.org/forum/index.php?action=dlattach;topic=8113.0;attach=2004')
- Downloading to disk...
Download file
Open "cmd"
"powershell -executionpolicy unrestricted -file get-exiftool.ps1"
- From powershell
Open powershell
Copy and paste the following
Function UnzipFile($argVar){
write-host $argVar
$shell_app=new-object -com shell.application
$zip_file = $shell_app.namespace($argVar)
Write-Host "Uncompressing the Zip file to $($targetondisk)" -ForegroundColor Cyan
$destination = $shell_app.namespace($targetondisk)
$destination.Copyhere($zip_file.items(), 0x10)
$shell_app = $null
}
$destDir = "$env:temp\" ; $targetondisk = "$env:USERPROFILE\apps\exiftool";
wget "http://www.exiftool.org/ver.txt" -OutFile "$targetondisk\ver.txt"
$ver = (gc "$targetondisk\ver.txt"); $url = "http://www.exiftool.org/exiftool-$ver.zip"; #thanks to Phil Harvey for the heads up
if (!(Test-Path $targetondisk)){New-Item -ItemType Directory -Force -Path $targetondisk | out-null};
$parsed = $url.Substring($url.LastIndexOf("/") + 1); $file = "$destDir$parsed";
if (!(Test-Path $file)){ start-bitstransfer -Destination $destDir $url };
if (!(Test-Path "$targetondisk\exiftool.exe")){ UnzipFile $file; Rename-Item "$targetondisk\exiftool(-k).exe" "$targetondisk\exiftool.exe" };
To run simply execute from command line:
%USERPROFILE%\apps\exiftool\exiftool.exe
Note: Tested on windows 10
Cheers
Thanks for the post.
You could make the script more useful if it could first download "http://www.exiftool.org/ver.txt" to get the current ExifTool version number, then use that to download/install the most recent version of ExifTool.
- Phil
Thanks Phil.
Firstly for this wonderful tool, and for the version check heads up. Updated script and post accordingly
Cheers
Nice.
Might I suggest replacing wget with invoke-webrequest, since that is the actual command being called? Powershell uses wget (and curl) as an alias for invoke-webrequest and is incompatible with actual wget command line options for those who actually use the real wget command.
I do want to thank you for this, careto. This script gave me the foundation for an auto-update script for exiftool, something I've wanted for a while. Powershell isn't my thing so my addition may be a bit raw, but I added a version check and removal of the files the script creates. Also made my previously mentioned change from wget to invoke-webrequest. It currently overwrites the previously installed exiftool, but I think a rename to backup the older version might be in order.
Function UnzipFile($argVar){
write-host $argVar
$shell_app=new-object -com shell.application
$zip_file = $shell_app.namespace($argVar)
Write-Host "Uncompressing the Zip file to $($targetondisk)" -ForegroundColor Cyan
$destination = $shell_app.namespace($targetondisk)
$destination.Copyhere($zip_file.items(), 0x10)
$shell_app = $null
}
$destDir = "$env:temp\" ; $targetondisk = "$env:USERPROFILE\apps\exiftool";
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
invoke-webrequest "http://www.exiftool.org/ver.txt" -OutFile "$targetondisk\ver.txt"
$ver = (gc "$targetondisk\ver.txt"); $url = "http://www.exiftool.org/exiftool-$ver.zip"; #thanks to Phil Harvey for the heads up
#version check
if (Test-Path "$targetondisk\exiftool.exe") {$currentVer = & "$targetondisk\exiftool.exe" "-ver" ; if ($currentVer -ge $ver) {Write-Host "Exiftool is up to date"; exit;} }
Write-Host "Updating exiftool from version $currentVer to $ver";
if (!(Test-Path $targetondisk)){New-Item -ItemType Directory -Force -Path $targetondisk | out-null};
$parsed = $url.Substring($url.LastIndexOf("/") + 1); $file = "$destDir$parsed";
if (!(Test-Path $file)){ start-bitstransfer -Destination $destDir $url };
UnzipFile $file; Move-Item -Force "$targetondisk\exiftool(-k).exe" "$targetondisk\exiftool.exe" ;
#cleanup
Remove-Item $file
Remove-Item $targetondisk\ver.txt
Minor update. My update script failed today with a "The request was aborted: Could not create SSL/TLS secure channel" error. It looks like www.sno.phy.queensu.ca has had a security update as following the answer in this StackOverflow answer (https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel) fixed it. All that needs to be done was add the [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 line. I'll edit my post in include it.