diff --git a/README.fr.md b/README.fr.md
index aabb5f3..21ebf28 100644
--- a/README.fr.md
+++ b/README.fr.md
@@ -31,15 +31,9 @@ Petite boîte à outils Windows pour installer des packs de logiciels libres ave
## ✅ Prérequis
-Lance les commandes depuis un **terminal administrateur** sous Windows.
+Lance les commandes depuis un **terminal administrateur** sous Windows. winget doit être disponible (App Installer depuis le Microsoft Store).
-Active d'abord la prise en charge des configurations winget :
-
-```powershell
-winget configure --enable
-```
-
-Les packs YAML automatisés n'imposent pas de version précise de Windows. Ils nécessitent un système Windows avec la prise en charge des configurations winget activée.
+Les packs YAML automatisés nécessitent winget 1.6 ou version ultérieure.
diff --git a/README.md b/README.md
index 7a3bc44..964e8bf 100644
--- a/README.md
+++ b/README.md
@@ -31,15 +31,9 @@ Small Windows toolkit to install libre software packs with `winget` and remove s
## ✅ Requirements
-Run the commands from an **administrator terminal** on Windows.
+Run the commands from an **administrator terminal** on Windows. winget must be available (App Installer from the Microsoft Store).
-Enable winget configuration support first:
-
-```powershell
-winget configure --enable
-```
-
-The automated YAML packs do not enforce a specific Windows release. They require a Windows system with winget configuration support enabled.
+The automated YAML packs require winget 1.6 or later.
diff --git a/powershell/Initialize-Winget.ps1 b/powershell/Initialize-Winget.ps1
new file mode 100644
index 0000000..20bd157
--- /dev/null
+++ b/powershell/Initialize-Winget.ps1
@@ -0,0 +1,72 @@
+# Shared helper: ensures winget is accessible before use.
+# Dot-source this script and call Initialize-Winget at startup.
+# Repair operations require administrator rights.
+
+function Initialize-Winget {
+ if (Get-Command winget -ErrorAction SilentlyContinue) {
+ return
+ }
+
+ Write-Host "winget not found in PATH. Attempting repair..." -ForegroundColor Yellow
+
+ # Refresh PATH from registry in case a recent install is not yet visible
+ $MachinePath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
+ $UserPath = [System.Environment]::GetEnvironmentVariable("PATH", "User")
+ $env:PATH = $MachinePath + ";" + $UserPath
+
+ if (Get-Command winget -ErrorAction SilentlyContinue) {
+ Write-Host "winget available after PATH refresh." -ForegroundColor Green
+ return
+ }
+
+ # Try to re-register the installed App Installer package
+ $AppInstaller = Get-AppxPackage -Name "Microsoft.DesktopAppInstaller" -ErrorAction SilentlyContinue
+ if (-not $AppInstaller) {
+ $AppInstaller = Get-AppxPackage -AllUsers -Name "Microsoft.DesktopAppInstaller" -ErrorAction SilentlyContinue
+ }
+
+ if ($AppInstaller) {
+ Write-Host "Re-registering App Installer..." -ForegroundColor Yellow
+ try {
+ $Manifest = Join-Path $AppInstaller.InstallLocation "AppxManifest.xml"
+ Add-AppxPackage -DisableDevelopmentMode -Register $Manifest -ErrorAction Stop
+ $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" +
+ [System.Environment]::GetEnvironmentVariable("PATH", "User")
+
+ if (Get-Command winget -ErrorAction SilentlyContinue) {
+ Write-Host "winget repaired." -ForegroundColor Green
+ return
+ }
+ }
+ catch {
+ Write-Warning "Re-registration failed: $_"
+ }
+ }
+
+ # Try to reinstall from the provisioned (staged) package on this machine
+ $StagedPackage = Get-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue |
+ Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" } |
+ Select-Object -First 1
+
+ if ($StagedPackage) {
+ Write-Host "Installing App Installer from provisioned package..." -ForegroundColor Yellow
+ try {
+ Add-AppxPackage -Path $StagedPackage.PackagePath -ErrorAction Stop
+ $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" +
+ [System.Environment]::GetEnvironmentVariable("PATH", "User")
+
+ if (Get-Command winget -ErrorAction SilentlyContinue) {
+ Write-Host "winget installed." -ForegroundColor Green
+ return
+ }
+ }
+ catch {
+ Write-Warning "Installation from provisioned package failed: $_"
+ }
+ }
+
+ Write-Error ("winget is not available and could not be repaired automatically.`n" +
+ "Install App Installer from the Microsoft Store: " +
+ "ms-windows-store://pdp/?productid=9nblggh4nns1")
+ exit 1
+}
diff --git a/powershell/Install-Firefox.ps1 b/powershell/Install-Firefox.ps1
index 1776359..7b2601a 100644
--- a/powershell/Install-Firefox.ps1
+++ b/powershell/Install-Firefox.ps1
@@ -9,6 +9,8 @@ param(
$ErrorActionPreference = "Stop"
+. (Join-Path $PSScriptRoot "Initialize-Winget.ps1")
+
$IsAdministrator = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator
)
@@ -23,10 +25,7 @@ function Install-FirefoxEsr {
[string]$PackageId
)
- if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
- Write-Error "winget was not found. Install App Installer or enable winget before running this script."
- exit 1
- }
+ Initialize-Winget
Write-Host "Installing Firefox ESR with winget: $PackageId" -ForegroundColor Cyan
diff --git a/powershell/Winget-Remove-BuiltInApps.ps1 b/powershell/Winget-Remove-BuiltInApps.ps1
index 5bd48ad..42393a8 100644
--- a/powershell/Winget-Remove-BuiltInApps.ps1
+++ b/powershell/Winget-Remove-BuiltInApps.ps1
@@ -1,6 +1,9 @@
# Requires running as administrator
# Uninstalling Windows applications via winget
+. (Join-Path $PSScriptRoot "Initialize-Winget.ps1")
+Initialize-Winget
+
$Packages = @(
"Windows Web Experience Pack",
"Xbox",
diff --git a/powershell/libres-softwares-install.ps1 b/powershell/libres-softwares-install.ps1
index b605ba3..f5bfda5 100644
--- a/powershell/libres-softwares-install.ps1
+++ b/powershell/libres-softwares-install.ps1
@@ -1,12 +1,8 @@
# Script d'installation de logiciels avec winget
# Permet de choisir les logiciels a installer
-# Verification que winget est installe
-if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
- Write-Host "ERREUR: winget n'est pas installe sur ce systeme." -ForegroundColor Red
- Write-Host "Veuillez installer le 'App Installer' depuis le Microsoft Store." -ForegroundColor Yellow
- exit 1
-}
+. (Join-Path $PSScriptRoot "Initialize-Winget.ps1")
+Initialize-Winget
Write-Host "===========================================================" -ForegroundColor Cyan
Write-Host " Script d'installation de logiciels avec winget" -ForegroundColor Cyan