Logo Pastebin.fr
Pastebin

Retrouvez, créez et partagez vos snippets en temps réel.

photofiltre

<#
install.ps1
But : détecter si PhotoFiltre est présent, sinon lancer l'installateur local (dans le même dossier que le script)
Usage (dans GPO PowerShell Scripts) :
 Script name: install.ps1
 Script parameters: -NoProfile -ExecutionPolicy Bypass
#>

# --- Logging
$LogFile = Join-Path -Path $env:TEMP -ChildPath "GPO_PhotoFiltre_install_$(($env:COMPUTERNAME)).log"
function Log {
    param($s)
    $t = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    "$t`t$s" | Out-File -FilePath $LogFile -Append -Encoding UTF8
}

Log "=== Début install PhotoFiltre ==="

# --- Helper : vérifie présence via la clé Uninstall (HKLM)
function Is-PhotoFiltreInstalled {
    try {
        $keys = @(
            "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
            "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
            "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        )
        foreach ($k in $keys) {
            if (Test-Path $k) {
                Get-ChildItem -Path $k -ErrorAction SilentlyContinue |
                ForEach-Object {
                    try { Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue } catch { $null }
                } |
                Where-Object { $_.DisplayName -and ($_.DisplayName -match "Photo ?Filtre") } |
                ForEach-Object { return $true }
            }
        }
    } catch {
        Log "Erreur detection install: $_"
    }
    return $false
}

if (Is-PhotoFiltreInstalled) {
    Log "PhotoFiltre déjà installé ; sortie."
    exit 0
}

# --- Localisation de l'installateur
# On suppose que l'installateur a été copié dans le même dossier que le script GPO
$ScriptFolder = Split-Path -Parent $MyInvocation.MyCommand.Definition
$PossibleNames = @("PhotoFiltreInstaller.exe","photofiltre.exe","PhotoFiltre_Studio.exe")
$Installer = $null
foreach ($n in $PossibleNames) {
    $p = Join-Path $ScriptFolder $n
    if (Test-Path $p) { $Installer = $p; break }
}

if (-not $Installer) {
    # fallback : tenter le partage NETLOGON (optionnel)
    $netlogonPath = "\\$env:USERDOMAIN\netlogon\PhotoFiltre\PhotoFiltreInstaller.exe"
    if (Test-Path $netlogonPath) { $Installer = $netlogonPath }
}

if (-not $Installer) {
    Log "Installateur introuvable. Chemins vérifiés: $ScriptFolder\* et $netlogonPath. Abandon."
    exit 1
}

Log "Installateur trouvé : $Installer"

# --- Tentatives de silent install avec plusieurs flags courants
$switches = @(
    "/S",               # NSIS
    "/silent",          # divers
    "/VERYSILENT",      # Inno
    "/SILENT",          # Inno alternative
    "/qn",              # MSI (si c'est un wrapper)
    "/quiet",           # autre
    "/install /quiet"   # some wrappers
)

$installed = $false
foreach ($s in $switches) {
    try {
        Log "Tentative d'installation avec switch: $s"
        $psi = Start-Process -FilePath $Installer -ArgumentList $s -Wait -PassThru -WindowStyle Hidden -ErrorAction Stop
        # Si Start-Process renvoie un objet, vérifier ExitCode si dispo
        if ($psi -and $psi.HasExited) {
            Log "Processus terminé, ExitCode=$($psi.ExitCode)"
        } else {
            Log "Processus lancé (pas d'ExitCode récupéré)."
        }
    } catch {
        Log "Erreur lancement de l'installateur avec $s : $_"
    }

    Start-Sleep -Seconds 5
    if (Is-PhotoFiltreInstalled) {
        $installed = $true
        Log "PhotoFiltre détecté après tentative $s"
        break
    } else {
        Log "Non installé après $s"
    }
}

if (-not $installed) {
    Log "Toutes les tentatives silencieuses échouées. Tentative d'exécution interactive en dernier recours (sans flags)."
    try {
        Start-Process -FilePath $Installer -Wait -PassThru
        Start-Sleep -Seconds 3
        if (Is-PhotoFiltreInstalled) { $installed = $true; Log "Install réussie après exécution interactive." }
    } catch {
        Log "Erreur exécution interactive: $_"
    }
}

if ($installed) {
    Log "Installation OK."
    exit 0
} else {
    Log "Échec installation PhotoFiltre."
    exit 1
}

Créé il y a 1 semaine.

Rechercher un Pastebin

Aucun paste trouvé.