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.


  • 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

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/PowerShell, 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/PowerShell, 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).

Beehaus

love this script, which I used as basis for a function below
additionally, this function renames the previous exe with a version number for backup as suggested
if it does not find Exiftool in the path, it will download the latest version anyway

Function Update-ExifTool($exiftoolPath){

    # init
    $url_ver = "http://www.exiftool.org/ver.txt"
    $exiftoolParent = Split-Path $exiftoolPath -Parent
    $exiftoolExe = Split-Path $exiftoolPath -Leaf
    $unzipped_filename = "$exiftoolParent\exiftool(-k).exe"

    # get existing version information locally
    if (test-path $exiftoolPath) { $existing_ver = ExifTool -Arguments "-ver" ; write-host "existing ExifTool version: $($existing_ver.Trim())" -f Green}
    else { $existing_ver = $null ; write-host "ExifTool not found" -f Green ; if (!(Test-Path $exiftoolParent)) { New-Item $exiftoolParent -ItemType Directory | Out-Null } }

    # get latest version information online
    $latest_ver = invoke-webrequest $url_ver -UseBasicParsing | select -ExpandProperty Content
    write-host "latest ExifTool version: $latest_ver" -f Green

    # update if required
    if ($latest_ver -gt $existing_ver) {
        $download_url = "http://www.exiftool.org/exiftool-$latest_ver.zip"
        $zip_filename = "$exiftoolParent\exiftool-$latest_ver.zip"
        if ($existing_ver -ne $null){
            $backup_filename = $exiftoolPath.Replace(".exe",".$($existing_ver.Trim())"+".old.exe")
            if (!(Test-Path $backup_filename)) { Rename-Item -Path $exiftoolPath -NewName $backup_filename }
            else { Remove-Item -Path $exiftoolPath -Force -Confirm:$false }
        }
        Start-BitsTransfer -Destination $exiftoolParent $download_url
        $shell_app = new-object -com shell.application
        $zip_obj = $shell_app.namespace($zip_filename)
        $destination = $shell_app.namespace($exiftoolParent)
        $destination.Copyhere($zip_obj.items(), 0x10)
        $shell_app = $null
        Remove-Item -Path $zip_filename -Force -Confirm:$false
        Rename-Item -Path $unzipped_filename -NewName $exiftoolPath
        Write-Host "updated to the latest version" -f Green

    }

    # no update required
    else { Write-Host "using latest version no update required" -f Green }

}

Update-ExifTool -exiftoolPath "C:\Exiftool\Exiftool.exe"