Showing posts with label metatag. Show all posts
Showing posts with label metatag. Show all posts

04 April, 2024

TeamViewer 'Console' - Manual automated update

 Some context may help...

We use TeamViewer to remotely support our users.

I don't know what the app used to manage / connect to others is actually called - So I call it the 'Console'.
'Host' is the client installed on all of the computers we support.

NOTE:
The 'Console' installs to this folder: C:\Program Files\TeamViewer\TeamViewer.exe
The 'Host' installs to this folder: C:\Program Files (x86)\TeamViewer\TeamViewer.exe


The console also acts as a 'Client' - So having the 'Client installed on my home computer, allows me to remote connect to my work computer and WFH easily... And conversely, from work, I can easily access my home computer, if needed.

From home - I kept running into (infrequently) not being able to connect to my work computer...
The computer would show, but as 'offline'...

  1. The updated file / installer would download...
  2. That installer would shutdown the current TeamViewer...
  3. And then the installer would fail to complete

(I think its ESET AV - but I am not going to try and explain this to my boss who controls that config - to much work - He turns everything into an argument.)

The end result - Teamviewer is not running, so I cant connect to the work computer...

I put together the below PoSh Script to get past the above problem...
It is a scheduled task that runs at 3AM every day - It takes about 6 minutes to complete
It downloads the most recent version of the Powershell 'Console'...
Compares the 'version info' of that download, to the 'version info' of the currently installed...

If needed, it proceeds to kill Teamviewer, and run the install from that download.
It presents a pop-up window beforehand with a warning, and other useful info...

After that completes, it restarts TeamViewer.
Verifies the downloaded vs. installed versions.

Even if no updates are needed - Regardless, it checks to see if TeamViewwer is running and if not will (attempt to) restart it.

Additionally, it logs all of the pertinent info (currently set to only hold 50 lines)
Log examples:
2024 APR 04, 03:08:39 AM | ~ UPDATED ~ From ver.: 15.52.3.0,  To ver.: 15.52.4.0 | Tv Running?: yes
2024 APR 04, 03:07:01 AM | Installed: 15.52.3.0 vs. Downloaded: 15.52.4.0 - Update needed?: YES | Tv Running?: yes
2024 APR 03, 03:06:55 AM | Installed: 15.52.3.0 vs. Downloaded: 15.52.3.0 - Update needed?: no | Tv Running?: yes
2024 APR 02, 03:06:55 AM | Installed: 15.52.3.0 vs. Downloaded: 15.52.3.0 - Update needed?: no | Tv Running?: yes


Here is the script (forgive my command abbreviations - That's just how I roll):

$LogFile_Path = "C:\Users\richie\Documents\PoSh_Stuff\TvUpdateReport.txt"

$DL_Path = "C:\Users\Public\Downloads"

$App_Path = "C:\Program Files\TeamViewer\TeamViewer.exe"
Function Running { Get-Process | ? { $_.Path -eq $App_Path } }

Function Report {"$Report`n$(gc $LogFile_Path | Select -First 50 | Out-String)" | Out-File $LogFile_Path -Force}

$URL = "https://download.teamviewer.com/download/TeamViewer_Setup_x64.exe"
$SaveFile = "$DL_Path\$(Split-path $URL -Leaf)" 
iwr -Uri "$URL" -OutFile $SaveFile

$DataInfo = gci $SaveFile | Select Name, FullName

If (!$DataInfo) {Break}
$DL_Path = ($DataInfo).FullName
#####################################
$shellfolder = $null; $shellfolder = (New-Object -COMObject Shell.Application).Namespace($(Split-Path ($DataInfo).FullName))
$shellfile = $null; $shellfile = $shellfolder.ParseName($(Split-Path ($DataInfo).FullName -Leaf))

$Downloaded = $null; $Downloaded = [System.Version]::Parse($($shellfolder.GetDetailsOf($shellfile, 166) )) # 166 is the metatag value for the "File version" tag.
$Installed = $null; $Installed = (Get-Item $App_Path).VersionInfo.FileVersionRaw

$D_version = "$($Downloaded.Major).$($Downloaded.Minor).$($Downloaded.Build).$($Downloaded.Revision)"
$I_version = "$($Installed.Major).$($Installed.Minor).$($Installed.Build).$($Installed.Revision)"
$NeedsUpdate = "no"
If ($Downloaded -gt $Installed) {$NeedsUpdate = "YES"}

$Tv_Running = "NO"; If ( Running ) { $Tv_Running = "yes" }
If ($Tv_Running -ne "yes") {Start $App_Path}

$FormatDate = $((Get-Date).ToString("yyyy '$(((Get-Culture).DateTimeFormat.GetAbbreviatedMonthName(((Get-Date)).Month)).ToUpper())' dd, hh:mm:ss tt"))
$Report = "$FormatDate | Installed: $I_version vs. Downloaded: $D_version - Update needed?: $NeedsUpdate | Tv Running?: $Tv_Running"
Report
##  gc $LogFile_Path

If (!$Downloaded -or !$Installed) {Break}
    If ($Downloaded -gt $Installed) {
        If ($Host.Name -match "ISE") { 
        ''; Write-Host "DOWNLOADED TeamViewer version:" -F 14 -B 2; Write-Host ($Downloaded | Out-String).Trim() -F 10
        ''; Write-Host "INSTALLED TeamViewer version:" -F 5 -B 14; Write-Host ($Installed | Out-String).Trim() -F 14
        }

$PopUpMsg = @"
In about 30 seconds...
TEAMVIEWER WILL SHUTDOWN...
It will be UPDATED... 
From: $Installed 
To  : $Downloaded
THEN Teamviewer will restart.

THIS TAKES ABOUT A MINUTE OR TWO.
You should then be able to reconnect to this comouter if needed.
"@
Msg /TIME:30 * $PopUpMsg
Sleep 29.5

Get-Process | ? {$_.Path -match "TeamViewer.exe" } | Stop-Process -Force
Sleep 3; cmd.exe /c "$SaveFile" /S
Sleep 3; Start $App_Path
}

If (!( Running )) {
Sleep 10; Start $App_Path
}

If ($Host.Name -match "ISE") { If ($Downloaded -le $Installed) { Write-Host "TeamViewer is Up-to-date..." -F 10 -B 2} }

If ($Downloaded -gt $Installed) {
$Prev_I_version = $I_version
$Installed = $null; $Installed = (Get-Item $App_Path).VersionInfo.FileVersionRaw
$I_version = "$($Installed.Major).$($Installed.Minor).$($Installed.Build).$($Installed.Revision)"
Sleep 10
$Tv_Running = "NO"; If ( Running ) { $Tv_Running = "yes" }
If ($Tv_Running -ne "yes") {Start $App_Path}

$FormatDate = $((Get-Date).ToString("yyyy '$(((Get-Culture).DateTimeFormat.GetAbbreviatedMonthName(((Get-Date)).Month)).ToUpper())' dd, hh:mm:ss tt"))
$Report = "$FormatDate | ~ UPDATED ~ From ver.: $Prev_I_version,  To ver.: $I_version | Tv Running?: $Tv_Running"
Report
##  gc $LogFile_Path
}

27 July, 2020

Query metatags, no extenal DLL's, or exe's needed.

This is my most recent discovery for auditing multiple audio file metatags...
These files are the back-up of my iPod

There's a lot more here than is needed - But I wanted it to look nice.

There is also plenty of comments and methods in it, to give you an idea on what kind of audits are possible.

Previously, I used ffprobe (part of ffmpeg) to read these tags... But it was kinds of slow...
What I used here, took less than half the time.

To see what I did with that "$NullQuery" from this script, see this post:
http://www.somethingtoscrollthrough.com/2020/07/command-line-search-ms.html


$NullQuery = @()
$NullCount = 0
$StartTime = (Get-Date)

$DrivesInfo = Get-WmiObject -Class Win32_logicaldisk
Write-Host "===========================" -ForegroundColor Cyan
$AudioSource = "$(($DrivesInfo | ? {$_.VolumeName -match "easystore"}).DeviceID)\iPod BackUp\iPod_Control\Music"
$_TitlesCounter = 0

$_Titles = $null
$_Titles = gci $AudioSource -Recurse -Force | ? {($_.Name -match ".m4a") -or ($_.Name -match ".mp3")}
$_TitlesTotal = $_Titles.Count

$_Titles | % {
$_TitlesCounter++

$path = $_.FullName # 'F:\iPod BackUp\iPod_Control\Music\F00\GNVD.mp3'
$shell = New-Object -COMObject Shell.Application
$folder = $_.DirectoryName  # Split-Path $path
$file = $_.Name  # Split-Path $path -Leaf
$shellfolder = $shell.Namespace($folder)
$shellfile = $shellfolder.ParseName($file)

$Label_Array = @(13,14,16,20,21,26,27,194,237)  | % { '{0} = {1}' -f $_, $shellfolder.GetDetailsOf($null, $_) }

$Label_Array | % {
$Set_Up = (($_).Split('=')).Split("`n|`r",[System.StringSplitOptions]::RemoveEmptyEntries)
#Write-Host  "$($Set_Up[1]): $($shellfolder.GetDetailsOf($shellfile, $Set_Up[0]))"
$Tag__ = ($Set_Up[1]).Trim()
$Tag__Value = $shellfolder.GetDetailsOf($shellfile, $Set_Up[0])

    $_FullName = ($path).ToUpper()

    If ( $Tag__ -eq "Authors") {
    $artist01 = "ARTIST"
    $artist02 = $Tag__Value
        If ($artist02 -eq "") {$artist02 = "NULL"}
    }

    If ( $Tag__ -eq "Title") {
    $title01 = ($Tag__).ToUpper()
    $title02 = $Tag__Value
        If ($title02 -eq "") {$title02 = "NULL"}
    }

    If ( $Tag__ -eq "Album") {
    $album01 = ($Tag__).ToUpper()
    $album02 = $Tag__Value
        If ($album02 -eq"") {$album02 = "NULL"}
    }

    If ( $Tag__ -eq "Album artist") {
    $albumArtist01 = ($Tag__).ToUpper()
    $albumArtist02 = $Tag__Value
        If ($albumArtist02 -eq "") {$albumArtist02 = "NULL"}
    }

    If ( $Tag__ -eq "#") {
    $track01 = "TRACK"
    $track02 = $Tag__Value
        If ($track02 -eq "") {$track02 = "NULL"}
    }

    If ( $Tag__ -eq "genre") {
    $genre01 = ($Tag__).ToUpper()
    $genre02 = $Tag__Value
        If ($genre02 -eq "") {$genre02 = "NULL"}
    }

} # END $Label_Array | %
##########################
    Write-Host "$_FullName" -ForegroundColor Cyan
        Write-Host "        $artist01`: " -NoNewline -ForegroundColor Yellow; Write-Host $artist02
        Write-Host "  $albumArtist01`: " -NoNewline -ForegroundColor Yellow; Write-Host $albumArtist02
        Write-Host "         $title01`: " -NoNewline -ForegroundColor Yellow; Write-Host $title02              
        Write-Host "         $album01`: " -NoNewline -ForegroundColor Yellow; Write-Host $album02
        Write-Host "         $track01`: " -NoNewline -ForegroundColor Yellow; Write-Host $track02
        Write-Host "         $genre01`: " -NoNewline -ForegroundColor Yellow; Write-Host $genre02
        Write-Host "===== Timer: $(((Get-Date) - $StartTime).Minutes) minutes ====== Total: $_TitlesCounter of $_TitlesTotal / Null: $NullCount" -ForegroundColor Green

        If (($artist02 -eq "NULL") -or ($title02 -eq "NULL")) {
        $NullCount++
        $QueryB = new-object psobject
        $QueryB | Add-Member -membertype noteproperty -name "FilePath" -Value $_FullName
        $QueryB | Add-Member -membertype noteproperty -name "File" -Value $file
        $QueryB | Add-Member -membertype noteproperty -name "Folder" -Value $folder
        $QueryB | Add-Member -membertype noteproperty -name "Artist" -Value $artist02
        $QueryB | Add-Member -membertype noteproperty -name "Album_Artist" -Value $albumArtist02
        $QueryB | Add-Member -membertype noteproperty -name "Title" -Value $title02
        $QueryB | Add-Member -membertype noteproperty -name "Album" -Value $album02
        $QueryB | Add-Member -membertype noteproperty -name "Track" -Value $track02
        $NullQuery += $QueryB
        Write-Host "#####################################" -ForegroundColor Magenta
        Start-Sleep -Milliseconds 1500
        }
Clear-Variable artist*
Clear-Variable title*
Clear-Variable album*
Clear-Variable track*
Clear-Variable genre*
##########################
}