function Write-Log { param ( [string]$Message, [string]$Level = "INFO" ) $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $logMessage = "[$timestamp] [$Level] $Message" Write-Output $logMessage Add-Content -Path "C:\DisableNetworkBanner.log" -Value $logMessage } if (-not (Test-Path "C:\DisableNetworkBanner.log")) { New-Item -Path "C:\DisableNetworkBanner.log" -ItemType File -Force | Out-Null } try { New-Item -Path "HKLM:\System\CurrentControlSet\Control\Network" -Name "NewNetworkWindowOff" -Force -ErrorAction SilentlyContinue | Out-Null netsh advfirewall firewall set rule group="Network Discovery" new enable=No | Out-Null if (-not (Test-Path "HKLM:\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet")) { New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet" -Force | Out-Null } New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet" -Name "EnableActiveProbing" -Value 0 -PropertyType DWord -Force | Out-Null $services = @("upnphost", "FDResPub", "SSDPSRV") foreach ($service in $services) { try { Set-Service -Name $service -StartupType Disabled -ErrorAction SilentlyContinue Stop-Service -Name $service -Force -ErrorAction SilentlyContinue } catch { Write-Log "Échec de la désactivation du service $service : $_" -Level "ERROR" } } $userProfiles = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" | Where-Object { $_.Name -like "*S-1-5-21*" } foreach ($profile in $userProfiles) { try { $sid = $profile.PSChildName $regPath = "Registry::HKEY_USERS\$sid\System\CurrentControlSet\Control\Network" if (Test-Path "Registry::HKEY_USERS\$sid") { if (-not (Test-Path $regPath)) { New-Item -Path $regPath -Force -ErrorAction SilentlyContinue | Out-Null } New-Item -Path $regPath -Name "NewNetworkWindowOff" -Force -ErrorAction SilentlyContinue | Out-Null } } catch { Write-Log "Erreur lors de la modification du profil $sid : $_" -Level "ERROR" } } $regCommands = @( 'reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\NetworkConnections" /v "NC_ShowSharedAccessUI" /t REG_DWORD /d 0 /f', 'reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\Network Connections" /v "NC_DoNotShowLocalOnlyIcon" /t REG_DWORD /d 1 /f', 'reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v "HideSCANetwork" /t REG_DWORD /d 1 /f' ) foreach ($cmd in $regCommands) { try { Invoke-Expression -Command "cmd.exe /c $cmd" | Out-Null Write-Log "Commande exécutée avec succès: $cmd" } catch { Write-Log "Échec de la commande: $cmd - $_" -Level "ERROR" } } Write-Log "Script terminé avec succès" -Level "SUCCESS" } catch { Write-Log "Erreur globale dans le script: $_" -Level "ERROR" }