Installation on windows with powershell

Started by careto, February 27, 2017, 09:10:25 AM

Previous topic - Next topic

careto

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.


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

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

careto

Thanks Phil.
Firstly for this wonderful tool, and for the version check heads up. Updated script and post accordingly
Cheers

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

#5
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
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

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 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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).