{"id":530395,"date":"2025-09-22T01:40:29","date_gmt":"2025-09-22T01:40:29","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=530395"},"modified":"2025-09-22T01:40:29","modified_gmt":"2025-09-22T01:40:29","slug":"modifier-les-parametres-d-economiseur-d-ecran-avec-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/fr\/script-hub\/modifier-les-parametres-d-economiseur-d-ecran-avec-powershell\/","title":{"rendered":"Comment modifier les param\u00e8tres d&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran avec PowerShell"},"content":{"rendered":"<p>Le contr\u00f4le des strat\u00e9gies d&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran est un \u00e9l\u00e9ment essentiel de la gestion des terminaux, en particulier dans les environnements soumis \u00e0 des exigences strictes en mati\u00e8re de conformit\u00e9 ou d&rsquo;image de marque. Qu&rsquo;il s&rsquo;agisse de renforcer la s\u00e9curit\u00e9 de l&rsquo;\u00e9cran de verrouillage ou de configurer un \u00e9conomiseur d&rsquo;\u00e9cran sp\u00e9cifique pour tous les profils d&rsquo;utilisateurs, l&rsquo;automatisation centralis\u00e9e peut faire gagner beaucoup de temps et d&rsquo;efforts aux professionnels de l&rsquo;informatique et aux <a href=\"https:\/\/www.ninjaone.com\/fr\/quest-ce-quun-msp\/\">fournisseurs de services g\u00e9r\u00e9s (MSP)<\/a>. Cet article explore un puissant script <a href=\"https:\/\/www.ninjaone.com\/it-hub\/endpoint-management\/what-is-powershell\/\">PowerShell<\/a> con\u00e7u pour\u00a0<strong>modifier les param\u00e8tres de l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran sur Windows avec PowerShell<\/strong>, offrant un contr\u00f4le fin \u00e0 grande \u00e9chelle.<\/p>\n<h2>Contexte<\/h2>\n<p>Pour les fournisseurs de services g\u00e9r\u00e9s et les administrateurs informatiques, s&rsquo;assurer que les param\u00e8tres de l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran sont conformes aux politiques de s\u00e9curit\u00e9 n&rsquo;est pas qu&rsquo;une question d&rsquo;apparence. Les cadres r\u00e9glementaires tels que <a href=\"https:\/\/www.ninjaone.com\/fr\/hipaa\/\">HIPAA<\/a> et PCI-DSS exigent souvent que les sessions inactives soient verrouill\u00e9es apr\u00e8s une dur\u00e9e d\u00e9termin\u00e9e. L&rsquo;application manuelle de ces configurations \u00e0 tous les profils est \u00e0 la fois source d&rsquo;erreurs et inefficace. La strat\u00e9gie de groupe peut \u00eatre utile, mais elle n&rsquo;est pas toujours disponible ou souhait\u00e9e, en particulier dans les environnements mixtes ou lors de la gestion de terminaux non reli\u00e9s \u00e0 un domaine. Ce script PowerShell comble cette lacune en modifiant directement le registre Windows pour chaque profil d&rsquo;utilisateur, fournissant un\u00a0<strong>script PowerShell pour modifier les param\u00e8tres d&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran<\/strong>\u00a0pour tous les utilisateurs d&rsquo;une machine.<\/p>\n<h2>Le script<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 5.1\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Change the screensaver settings for all user profiles on a Windows machine.\r\n.DESCRIPTION\r\n    Change the screensaver settings for all user profiles on a Windows machine.\r\nBy using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https:\/\/www.ninjaone.com\/terms-of-use.\r\n    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. \r\n    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. \r\n    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. \r\n    Warranty Disclaimer: The script is provided \u201cas is\u201d and \u201cas available\u201d, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. \r\n    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. \r\n    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. \r\n    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).\r\n\r\n.PARAMETER SelectScreensaver \"Bubbles\"\r\n    Select the screensaver to apply. If 'None' is selected, the screensaver will be disabled. Options include: None, 3D Text, Blank, Bubbles, Photos, Mystify, Ribbons\r\n\r\n.PARAMETER WaitTime\r\n    Specify the wait time in minutes before the screensaver activates. Valid values range from 1 to 9999 minutes. If no value is provided, the default wait time of 15 minutes will be used\r\n\r\n.PARAMETER OnResumeEnterPassword\r\n    Choose whether to require the user to log in on resume.\r\n\r\n.PARAMETER PhotosDirectoryPath\r\n    Enter the path to the directory containing the images for the 'Photos' screensaver. This must be a local path on the device. If 'Photos' is selected but this is not filled out, the default of each user's Pictures folder will be used.\r\n\r\n.PARAMETER TextFor3DText\r\n    Enter the text for the 3D Text screensaver. Only required if 3D Text is selected. Maximum length is 20 characters.\r\n\r\n.PARAMETER ForceReboot\r\n    Reboot the device after applying the screensaver settings. This may be needed for all changes to take effect. If not selected, the user may need to log off or restart their computer.\r\n    \r\n.EXAMPLE\r\n    -SelectScreensaver \"Ribbons\" -WaitTime 10 -OnResumeEnterPassword:$False\r\n    [Info] Working on 'tuser1' profile...\r\n\r\n    [Info] Setting screensaver to 'Ribbons'.\r\n    Registry::HKEY_USERS\\S-1-5-21-21640437-1735840450-3283185940-1104\\Control Panel\\Desktop\\SCRNSAVE.EXE changed from C:\\Windows\\System32\\Mystify.scr to C:\\Windows\\System32\\Ribbons.scr\r\n\r\n    [Info] Setting screensaver timeout to 10 minute(s).\r\n    Registry::HKEY_USERS\\S-1-5-21-21640437-1735840450-3283185940-1104\\Control Panel\\Desktop\\ScreenSaveTimeOut changed from 900 to 600\r\n\r\n    [Info] Setting screensaver password requirement to False.\r\n    Registry::HKEY_USERS\\S-1-5-21-21640437-1735840450-3283185940-1104\\Control Panel\\Desktop\\ScreenSaverIsSecure changed from 1 to 0\r\n\r\n    [Info] Finished working on 'tuser1' profile.\r\n\r\n.EXAMPLE\r\n    -SelectScreensaver \"Mystify\" -WaitTime 1 -OnResumeEnterPassword:$True\r\n    [Info] Working on 'tuser1' profile...\r\n\r\n    [Info] Setting screensaver to 'Mystify'.\r\n    Registry::HKEY_USERS\\S-1-5-21-21640437-1735840450-3283185940-1104\\Control Panel\\Desktop\\SCRNSAVE.EXE changed from C:\\Windows\\System32\\Ribbons.scr to C:\\Windows\\System32\\Mystify.scr\r\n\r\n    [Info] Setting screensaver timeout to 1 minute(s).\r\n    Registry::HKEY_USERS\\S-1-5-21-21640437-1735840450-3283185940-1104\\Control Panel\\Desktop\\ScreenSaveTimeOut changed from 900 to 60\r\n\r\n    [Info] Setting screensaver password requirement to True.\r\n    Registry::HKEY_USERS\\S-1-5-21-21640437-1735840450-3283185940-1104\\Control Panel\\Desktop\\ScreenSaverIsSecure changed from 0 to 1\r\n\r\n    [Info] Finished working on 'tuser1' profile.\r\n\r\n.EXAMPLE\r\n    -SelectScreensaver \"3D Text\" -WaitTime 5 -OnResumeEnterPassword:$False -TextFor3DText \"Hello World\"\r\n    [Info] Working on 'tuser1' profile...\r\n\r\n    [Info] Setting screensaver to '3D Text'.\r\n    Registry::HKEY_USERS\\S-1-5-21-21640437-1735840450-3283185940-1104\\Control Panel\\Desktop\\SCRNSAVE.EXE changed from C:\\Windows\\System32\\Mystify.scr to C:\\Windows\\System32\\ssText3d.scr\r\n\r\n    [Info] Setting screensaver timeout to 5 minute(s).\r\n    Registry::HKEY_USERS\\S-1-5-21-21640437-1735840450-3283185940-1104\\Control Panel\\Desktop\\ScreenSaveTimeOut changed from 60 to 300\r\n\r\n    [Info] Setting screensaver password requirement to False.\r\n    Registry::HKEY_USERS\\S-1-5-21-21640437-1735840450-3283185940-1104\\Control Panel\\Desktop\\ScreenSaverIsSecure changed from 1 to 0\r\n\r\n    [Info] Setting 3D Text to 'Hello World'.\r\n    Registry::HKEY_USERS\\S-1-5-21-21640437-1735840450-3283185940-1104\\Software\\Microsoft\\Windows\\CurrentVersion\\Screensavers\\ssText3d\\DisplayString changed from newvalue23 to Hello World\r\n\r\n    [Info] Finished working on 'tuser1' profile.\r\n\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 10, Windows Server 2016\r\n    Release Notes: Initial Release\r\n#&gt;\r\n\r\n[CmdletBinding()]\r\nparam (\r\n    [Parameter()]\r\n    [string]$SelectScreensaver,\r\n\r\n    [Parameter()]\r\n    [int]$WaitTime,\r\n\r\n    [Parameter()]\r\n    [switch]$OnResumeEnterPassword = [System.Convert]::ToBoolean($env:onResumeEnterPassword),\r\n\r\n    [Parameter()]\r\n    [string]$TextFor3DText,\r\n\r\n    [Parameter()]\r\n    [string]$PhotosDirectoryPath,\r\n    \r\n    [Parameter()]\r\n    [switch]$ForceReboot = [System.Convert]::ToBoolean($env:forceReboot)\r\n)\r\n\r\nbegin {\r\n    function Test-IsElevated {\r\n        [CmdletBinding()]\r\n        param ()\r\n        \r\n        # Get the current Windows identity of the user running the script\r\n        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()\r\n        \r\n        # Create a WindowsPrincipal object based on the current identity\r\n        $p = New-Object System.Security.Principal.WindowsPrincipal($id)\r\n        \r\n        # Check if the current user is in the Administrator role\r\n        # The function returns $True if the user has administrative privileges, $False otherwise\r\n        # 544 is the value for the Built In Administrators role\r\n        # Reference: https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.security.principal.windowsbuiltinrole\r\n        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]'544')\r\n    }\r\n\r\n    function Set-RegKey {\r\n        [CmdletBinding()]\r\n        param (\r\n            [Parameter()]\r\n            [String]$Path,\r\n            [Parameter()]\r\n            [String]$Name,\r\n            [Parameter()]\r\n            $Value,\r\n            [Parameter()]\r\n            [ValidateSet(\"DWord\", \"QWord\", \"String\", \"ExpandedString\", \"Binary\", \"MultiString\", \"Unknown\")]\r\n            [String]$PropertyType = \"DWord\"\r\n        )\r\n    \r\n        if ([String]::IsNullOrWhiteSpace($Path)) {\r\n            throw (New-Object System.ArgumentNullException(\"You must provide a valid path to a registry key.\"))\r\n        }\r\n    \r\n        if ($Path -notmatch \"^(Registry::|HKCR:\\\\|HKCU:\\\\|HKLM:\\\\|HKU:\\\\|HKCC:\\\\|TestRegistry:\\\\)\") {\r\n            throw (New-Object System.ArgumentException(\"The path provided '$Path' is invalid as it does not start with 'Registry::', 'HKCR:\\', 'HKCU:\\', 'HKLM:\\', 'HKU:\\' or 'HKCC:\\'.\"))\r\n        }\r\n    \r\n        if ($Path -match \"^Registry::\" -and $Path -notmatch \"^Registry::(HKCR\\\\|HKEY_CLASSES_ROOT\\\\|HKCU\\\\|HKEY_CURRENT_USER\\\\|HKLM\\\\|HKEY_LOCAL_MACHINE|HKU\\\\|HKEY_USERS|HKCC\\\\|HKEY_CURRENT_CONFIG)\") {\r\n            throw (New-Object System.ArgumentException(\"The path provided '$Path' is invalid as it does not start with a valid registry root such as 'HKLM\\' or 'HKEY_LOCAL_MACHINE\\'.\"))\r\n        }\r\n    \r\n        if ([String]::IsNullOrWhiteSpace($Name)) {\r\n            throw (New-Object System.ArgumentNullException(\"You must provide a valid name for the registry property.\"))\r\n        }\r\n    \r\n        # Check if the specified registry path exists\r\n        if (!(Test-Path -Path $Path)) {\r\n            try {\r\n                # If the path does not exist, create it\r\n                New-Item -Path $Path -Force -ErrorAction Stop | Out-Null\r\n            }\r\n            catch {\r\n                throw $_\r\n            }\r\n        }\r\n    \r\n        # Check if the registry key already exists at the specified path\r\n        if (Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue) {\r\n            # Retrieve the current value of the registry key\r\n            $CurrentValue = (Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue).$Name\r\n            if ($CurrentValue -eq $Value) {\r\n                Write-Host \"$Path\\$Name is already the value '$Value'.\"\r\n            }\r\n            else {\r\n                try {\r\n                    # Update the registry key with the new value\r\n                    Set-ItemProperty -Path $Path -Name $Name -Value $Value -Force -Confirm:$false -ErrorAction Stop | Out-Null\r\n                }\r\n                catch {\r\n                    throw $_\r\n                }\r\n    \r\n                # Output the change made to the registry key\r\n                Write-Host \"$Path\\$Name changed from $CurrentValue to $((Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue).$Name)\"\r\n            }\r\n    \r\n            return\r\n        }\r\n    \r\n        try {\r\n            # If the registry key does not exist, create it with the specified value and property type\r\n            New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $PropertyType -Force -Confirm:$false -ErrorAction Stop | Out-Null\r\n        }\r\n        catch {\r\n            throw $_\r\n        }\r\n    \r\n        # Output the creation of the new registry key\r\n        Write-Host \"Set $Path\\$Name to $((Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue).$Name)\"\r\n    }\r\n\r\n    function Get-UserHives {\r\n        [CmdletBinding()]\r\n        param (\r\n            [Parameter()]\r\n            [ValidateSet('AzureAD', 'DomainAndLocal', 'All')]\r\n            [String]$Type = \"All\",\r\n            [Parameter()]\r\n            [String[]]$ExcludedUsers,\r\n            [Parameter()]\r\n            [switch]$IncludeDefault\r\n        )\r\n    \r\n        # Define the SID patterns to match based on the selected user type\r\n        $Patterns = switch ($Type) {\r\n            \"AzureAD\" { \"S-1-12-1-(\\d+-?){4}$\" }\r\n            \"DomainAndLocal\" { \"S-1-5-21-(\\d+-?){4}$\" }\r\n            \"All\" { \"S-1-12-1-(\\d+-?){4}$\" ; \"S-1-5-21-(\\d+-?){4}$\" }\r\n        }\r\n    \r\n        # Retrieve user profile information based on the defined patterns\r\n        $UserProfiles = Foreach ($Pattern in $Patterns) { \r\n            Get-ItemProperty \"Registry::HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\*\" |\r\n                Where-Object { $_.PSChildName -match $Pattern } | \r\n                Select-Object @{Name = \"SID\"; Expression = { $_.PSChildName } },\r\n                @{Name = \"Username\"; Expression = { \"$($_.ProfileImagePath | Split-Path -Leaf)\" } }, \r\n                @{Name = \"Domain\"; Expression = { if ($_.PSChildName -match \"S-1-12-1-(\\d+-?){4}$\") { \"AzureAD\" }else { $Null } } }, \r\n                @{Name = \"UserHive\"; Expression = { \"$($_.ProfileImagePath)\\NTuser.dat\" } }, \r\n                @{Name = \"Path\"; Expression = { $_.ProfileImagePath } }\r\n        }\r\n    \r\n        # If the IncludeDefault switch is set, add the Default profile to the results\r\n        switch ($IncludeDefault) {\r\n            $True {\r\n                $DefaultProfile = \"\" | Select-Object Username, SID, UserHive, Path\r\n                $DefaultProfile.Username = \"Default\"\r\n                $DefaultProfile.Domain = $env:COMPUTERNAME\r\n                $DefaultProfile.SID = \"DefaultProfile\"\r\n                $DefaultProfile.Userhive = \"$env:SystemDrive\\Users\\Default\\NTUSER.DAT\"\r\n                $DefaultProfile.Path = \"C:\\Users\\Default\"\r\n    \r\n                # Exclude users specified in the ExcludedUsers list\r\n                $DefaultProfile | Where-Object { $ExcludedUsers -notcontains $_.Username }\r\n            }\r\n        }\r\n    \r\n        if ($PSVersionTable.PSVersion.Major -lt 3) {\r\n            $AllAccounts = Get-WmiObject -Class \"win32_UserAccount\"\r\n        }\r\n        else {\r\n            $AllAccounts = Get-CimInstance -ClassName \"win32_UserAccount\"\r\n        }\r\n    \r\n        $CompleteUserProfiles = $UserProfiles | ForEach-Object {\r\n            $SID = $_.SID\r\n            $Win32Object = $AllAccounts | Where-Object { $_.SID -like $SID }\r\n    \r\n            if ($Win32Object) {\r\n                $Win32Object | Add-Member -NotePropertyName UserHive -NotePropertyValue $_.UserHive \r\n                $Win32Object | Add-Member -NotePropertyName Path -NotePropertyValue $_.Path\r\n                $Win32Object\r\n            }\r\n            else {\r\n                [PSCustomObject]@{\r\n                    Name     = $_.Username\r\n                    Domain   = $_.Domain\r\n                    SID      = $_.SID\r\n                    UserHive = $_.UserHive\r\n                    Path     = $_.Path\r\n                }\r\n            }\r\n        }\r\n    \r\n        # Return the list of user profiles, excluding any specified in the ExcludedUsers list\r\n        $CompleteUserProfiles | Where-Object { $ExcludedUsers -notcontains $_.Name }\r\n    }\r\n\r\n    # Import the needed functions for working with PIDLs (Pointer to an Item Identifier List) into the Shell32 class\r\n    Add-Type -TypeDefinition @\"\r\nusing System;\r\nusing System.Runtime.InteropServices;\r\n\r\npublic class Shell32 {\r\n    \/\/ Converts a file or folder path into a PIDL (Pointer to an Item Identifier List)\r\n    [DllImport(\"shell32.dll\", CharSet = CharSet.Unicode)]\r\n    public static extern int SHParseDisplayName(string pszName, IntPtr pbc, out IntPtr ppidl, uint sfgaoIn, out uint psfgaoOut);\r\n\r\n    \/\/ Converts a PIDL into a file or folder path\r\n    [DllImport(\"shell32.dll\", CharSet = CharSet.Unicode)]\r\n    public static extern int SHGetPathFromIDList(IntPtr pidl, char[] pszPath);\r\n\r\n    \/\/ Retrieves the size of of an item ID list\r\n    [DllImport(\"shell32.dll\", CharSet = CharSet.Unicode)]\r\n    public static extern int ILGetSize(IntPtr pidl);\r\n\r\n    \/\/ Used to free memory\r\n    [DllImport(\"ole32.dll\")]\r\n    public static extern void CoTaskMemFree(IntPtr pv);\r\n}\r\n\"@ -Language CSharp\r\n\r\n    # Function to convert a path to a PIDL\r\n    function Convert-PathToPIDL {\r\n        param (\r\n            [string]$Path\r\n        )\r\n\r\n        # Initialize the PIDL to zero\r\n        $returnPIDL = [IntPtr]::Zero\r\n\r\n        try {\r\n            # Call SHParseDisplayName to get the PIDL from the provided path\r\n            # https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/shlobj_core\/nf-shlobj_core-shparsedisplayname\r\n            $result = [Shell32]::SHParseDisplayName($Path, [IntPtr]::Zero, [ref]$returnPIDL, 0, [ref][uint32]0)\r\n\r\n            # Check if the call was successful\r\n            if ($result -ne 0) {\r\n                throw \"Failed to retrieve PIDL for path: $Path (Error Code: $result)\"\r\n            }\r\n\r\n            # Return the PIDL\r\n            return $returnPIDL\r\n        }\r\n        catch {\r\n            throw $_\r\n        }\r\n    }\r\n\r\n    # Function to get the size of a PIDL\r\n    function Get-PIDLSize {\r\n        param (\r\n            [IntPtr]$PIDL\r\n        )\r\n\r\n        try {\r\n            # Call the Shell32.dll ILGetSize function\r\n            # https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/shlobj_core\/nf-shlobj_core-ilgetsize\r\n            $Size = [Shell32]::ILGetSize($PIDL)\r\n            return $Size\r\n        }\r\n        catch {\r\n            throw $_\r\n        }\r\n    }\r\n\r\n    # Function to encode a path into a Base64 encoded PIDL\r\n    # This is used to set the photo screensaver folder via the registry\r\n    function Get-EncryptedPIDLStringFromPath {\r\n        param (\r\n            [string]$Path\r\n        )\r\n\r\n        try {\r\n            # Get the PIDL from the path\r\n            $PIDL = Convert-PathToPIDL $Path\r\n\r\n            # Get the size of the PIDL structure\r\n            $SizeOfPIDL = Get-PIDLSize $PIDL\r\n\r\n            # Create a new byte array the size of the PIDL\r\n            $ByteArray = New-Object byte[] $SizeOfPIDL\r\n            \r\n            # Copy the PIDL data into the byte array\r\n            # https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.runtime.interopservices.marshal.copy?view=net-9.0#system-runtime-interopservices-marshal-copy(system-intptr-system-byte()-system-int32-system-int32)\r\n            [System.Runtime.InteropServices.Marshal]::Copy($PIDL, $ByteArray, 0, $SizeOfPIDL)\r\n\r\n            # Encode the byte array to a Base64 string\r\n            $Base64EncodedString = [System.Convert]::ToBase64String($ByteArray)\r\n\r\n            return $Base64EncodedString\r\n        }\r\n        catch {\r\n            throw $_\r\n        }\r\n        finally {\r\n            # Free the unmanaged PIDL memory\r\n            if ($PIDL -ne [IntPtr]::Zero -and $null -ne $PIDL) {\r\n                [Shell32]::CoTaskMemFree($PIDL)\r\n            }\r\n        }\r\n    }\r\n\r\n    # Function to convert a Base64 encoded PIDL back to a path\r\n    function Convert-PIDLToPath {\r\n        param (\r\n            [string]$EncodedPIDL\r\n        )\r\n    \r\n        # Decode the Base64 string to a byte array\r\n        $DecodedBytes = [System.Convert]::FromBase64String($EncodedPIDL)\r\n    \r\n        try {\r\n            # Allocate memory for the PIDL\r\n            $DecodedPIDLPointer = [System.Runtime.InteropServices.Marshal]::AllocCoTaskMem($DecodedBytes.Length)\r\n    \r\n            # Copy the decoded bytes to the allocated memory\r\n            # https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.runtime.interopservices.marshal.copy?view=net-9.0#system-runtime-interopservices-marshal-copy(system-byte()-system-int32-system-intptr-system-int32)\r\n            [System.Runtime.InteropServices.Marshal]::Copy($DecodedBytes, 0, $DecodedPIDLPointer, $DecodedBytes.Length)\r\n            \r\n            # Create buffer to hold the path\r\n            # The buffer size is 261 characters (Windows default max path length of 260 + null terminator)\r\n            $PathBuffer = New-Object char[] 261\r\n    \r\n            # Call SHGetPathFromIDList to get the path from the PIDL\r\n            # The first parameter is a point to where the data is, the second is where the path will be stored \r\n            # The function returns 0 on success\r\n            $Result = [Shell32]::SHGetPathFromIDList($DecodedPIDLPointer, $PathBuffer)\r\n            \r\n            # Throw if error occurred\r\n            if ($Result -eq 0) {\r\n                throw \"Failed to retrieve path from PIDL.\"\r\n            }\r\n    \r\n            # Return the decoded path as a string\r\n            return -join $PathBuffer\r\n        }\r\n        catch {\r\n            throw $_\r\n        }\r\n        finally {\r\n            # Free the allocated memory\r\n            if ($DecodedPIDLPointer -ne [IntPtr]::Zero) {\r\n                [System.Runtime.InteropServices.Marshal]::FreeCoTaskMem($DecodedPIDLPointer)\r\n            }\r\n        }\r\n    }\r\n}\r\nprocess {\r\n    try {\r\n        $IsElevated = Test-IsElevated -ErrorAction Stop\r\n    }\r\n    catch {\r\n        Write-Host -Object \"[Error] $($_.Exception.Message)\"\r\n        Write-Host -Object \"[Error] Unable to determine if the account '$env:Username' is running with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n    \r\n    if (!$IsElevated) {\r\n        Write-Host -Object \"[Error] Access Denied: Please run with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n\r\n    # Import script variables\r\n    if ($env:selectScreensaver) {$selectScreensaver = $env:selectScreensaver}\r\n    if ($env:waitTime) {\r\n        if ([int]::TryParse($env:waitTime, [ref]$null)) {\r\n            $waitTime = [int]$env:waitTime\r\n        }\r\n        else {\r\n            Write-Host \"[Error] The wait time must be a valid integer between 1 and 9999 minutes. Please enter a valid wait time.\"\r\n            exit 1\r\n        }\r\n    }\r\n    if (-not [string]::IsNullOrWhiteSpace($env:textFor3DText)) {$textFor3DText = $env:textFor3DText.Trim()}\r\n    if (-not [string]::IsNullOrWhiteSpace($env:photosDirectoryPath)) {$photosDirectoryPath = $env:photosDirectoryPath.Trim()}\r\n\r\n    # Map screensaver dropdown value to SCR file name\r\n    $screensaverMap = @{\r\n        \"None\"    = \"\"\r\n        \"3D Text\" = \"ssText3d.scr\"\r\n        \"Blank\"   = \"scrnsave.scr\"\r\n        \"Bubbles\" = \"Bubbles.scr\"\r\n        \"Photos\"  = \"PhotoScreensaver.scr\"\r\n        \"Mystify\" = \"Mystify.scr\"\r\n        \"Ribbons\" = \"Ribbons.scr\"\r\n    }\r\n\r\n    # Validate the selected screensaver\r\n    if (-not [string]::IsNullOrWhiteSpace($SelectScreensaver) -and -not $screensaverMap.ContainsKey($SelectScreensaver)) {\r\n        Write-Host \"[Error] Invalid screen saver selected. Valid options are: $($screensaverMap.Keys -join ', ')\"\r\n        exit 1\r\n    }\r\n\r\n    # Validate 3D Text is provided\r\n    if ($SelectScreensaver -eq \"3D Text\" -and [string]::IsNullOrWhiteSpace($textFor3DText)) {\r\n        Write-Host \"[Error] 3D Text screensaver requires text to be provided.\"\r\n        exit 1\r\n    }\r\n\r\n    # Warn if 3D Text is not selected but text is provided\r\n    if ($SelectScreensaver -ne \"3D Text\" -and -not [string]::IsNullOrWhiteSpace($TextFor3DText)) {\r\n        Write-Host \"[Warning] 3D Text was not selected as the screensaver. Ignoring provided Text for 3D Text input.`n\"\r\n        $textFor3DText = $null\r\n    }\r\n\r\n    # Validate character length of 3D Text\r\n    if ($SelectScreensaver -eq \"3D Text\" -and $TextFor3DText.Length -gt 20) {\r\n        Write-Host \"[Error] 3D Text exceeds the maximum length of 20 characters.\"\r\n        exit 1\r\n    }\r\n\r\n    # Warn if Photos is not selected but path is provided\r\n    if ($SelectScreensaver -ne \"Photos\" -and -not [string]::IsNullOrWhiteSpace($PhotosDirectoryPath)) {\r\n        Write-Host \"[Warning] Photos was not selected as the screensaver. Ignoring provided Photos Directory Path input.`n\"\r\n        $PhotosDirectoryPath = $null\r\n    }\r\n\r\n    # Error if the provided photos path is a UNC path\r\n    if ($SelectScreensaver -eq \"Photos\" -and $PhotosDirectoryPath -and $PhotosDirectoryPath -match \"^\\\\\\\\\") {\r\n        Write-Host \"[Error] UNC paths cannot be used for the Photos screensaver. Please provide a local path.\"\r\n        exit 1\r\n    }\r\n\r\n    # Error if photos path is not a local path\r\n    if ($SelectScreensaver -eq \"Photos\" -and $PhotosDirectoryPath -and $PhotosDirectoryPath -notmatch \"^[a-zA-Z]:\\\\\") {\r\n        Write-Host \"[Error] The provided photo directory path '$PhotosDirectoryPath' is not a valid local path.\"\r\n        exit 1\r\n    }\r\n\r\n    # Validate character length of the photos directory path\r\n    if ($SelectScreensaver -eq \"Photos\" -and $PhotosDirectoryPath -and $PhotosDirectoryPath.Length -gt 260) {\r\n        Write-Host \"[Error] The provided photo directory path '$PhotosDirectoryPath' exceeds the maximum length of 260 characters.\"\r\n        exit 1\r\n    }\r\n\r\n    # Set default photos path if photos is selected but no path provided\r\n    if ($SelectScreensaver -eq \"Photos\" -and [string]::IsNullOrWhiteSpace($PhotosDirectoryPath)) {\r\n        Write-Host \"[Warning] No path chosen for Photos directory. Defaulting to each user's Pictures folder.\"\r\n        $defaultPhotosPath = $true\r\n    }\r\n    elseif ($SelectScreensaver -eq \"Photos\") {\r\n        # Otherwise, validate the provided path\r\n        # Error if the provided path doesn't exist\r\n        if (-not (Test-Path -Path $PhotosDirectoryPath)) {\r\n            Write-Host \"[Error] The provided photo directory path '$PhotosDirectoryPath' does not exist.\"\r\n            exit 1\r\n        }\r\n\r\n        # Error if the provided path is not a directory\r\n        if (-not (Test-Path -Path $PhotosDirectoryPath -PathType Container)) {\r\n            Write-Host \"[Error] The provided photo directory path '$PhotosDirectoryPath' is not a directory.\"\r\n            exit 1\r\n        }\r\n    }\r\n\r\n    # Skip all other options if 'None' is selected as the screensaver\r\n    # Only warn the user if they specified another option\r\n    if ($SelectScreensaver -eq \"None\") {\r\n        if ($WaitTime -or $OnResumeEnterPassword -or $TextFor3DText -or $PhotosDirectoryPath) {\r\n            Write-Host \"[Warning] When 'None' is selected as the screensaver, all other options will be ignored.`n\"\r\n        }\r\n        $SkipAllSettings = $true\r\n    }\r\n    else {\r\n        # Check for wait time, if not provided fall back to 15 mins\r\n        # If it is provided, check if it is a valid integer\r\n        if ($waitTime -eq 0) {\r\n            Write-Host \"[Warning] Wait time not provided. Defaulting to 15 minutes.`n\"\r\n            $waitTime = 15\r\n        }\r\n        elseif ($waitTime -lt 0 -or $waitTime -gt 9999) {\r\n            Write-Host \"[Error] The minimum wait time is 1 minute, the maximum is 9999 minutes. Please enter a valid wait time.\"\r\n            exit 1\r\n        }\r\n    }\r\n\r\n    # Warn if force reboot is not selected and a setting is being changed\r\n    if (-not $ForceReboot) {\r\n        Write-Host \"[Warning] Force reboot not selected. Changes to screensaver settings may not take effect until the user logs off or restarts their computer.`n\"\r\n    }\r\n\r\n    $ExitCode = 0\r\n\r\n    # Get all user profiles on the machine\r\n    $UserProfiles = Get-UserHives -Type \"All\"\r\n\r\n    # Create list to hold loaded profiles\r\n    # This is used to unload the profiles after the script has run\r\n    $ProfileWasLoaded = New-Object System.Collections.Generic.List[object]\r\n    \r\n    # Loop through each profile on the machine\r\n    foreach ($UserProfile in $UserProfiles) {\r\n        # Store current user SID in variable\r\n        $currentUserSID = $UserProfile.SID\r\n        \r\n        # Load User ntuser.dat if it's not already loaded\r\n        if (!(Test-Path -Path Registry::HKEY_USERS\\$currentUserSID -ErrorAction SilentlyContinue)) {\r\n            try {\r\n                Start-Process -FilePath \"cmd.exe\" -ArgumentList \"\/C reg.exe LOAD HKU\\$currentUserSID `\"$($UserProfile.UserHive)`\"\" -Wait -WindowStyle Hidden\r\n                $ProfileWasLoaded.Add($UserProfile)\r\n            }\r\n            catch {\r\n                Write-Host \"[Error] Error loading the profile for '$($UserProfile.Name)'.\"\r\n                Write-Host \"[Error] $($_.Exception.Message)\"\r\n                $ExitCode = 1\r\n                continue\r\n            }\r\n        }\r\n\r\n        Write-Host \"[Info] Working on '$($UserProfile.Name)' profile...`n\"\r\n\r\n        # Set registry base path for the current user\r\n        $regPath = \"Registry::HKEY_USERS\\$currentUserSID\\Control Panel\\Desktop\"\r\n\r\n        # Get current values for later comparison\r\n        $currentValues = Get-ItemProperty -Path $regPath -ErrorAction SilentlyContinue\r\n        $currentScreensaver = $currentValues.\"SCRNSAVE.EXE\"\r\n\r\n        # If a screensaver has been selected, set or remove it\r\n        if (-not [string]::IsNullOrWhiteSpace($SelectScreensaver)){\r\n            if ($SelectScreensaver -eq \"None\") {\r\n                $currentScreenSaverIsSecure = $currentValues.\"ScreenSaverIsSecure\"\r\n                $currentScreenSaverTimeout = $currentValues.\"ScreenSaveTimeout\"\r\n\r\n                # Create array of values to check if screensaver is active\r\n                $combined = @($currentScreensaver, $currentScreenSaverIsSecure, $currentScreenSaverTimeout)\r\n\r\n                if ([string]::IsNullOrWhiteSpace($combined)) {\r\n                    Write-Host \"[Info] Screensaver is already disabled.\"\r\n                }\r\n                else {\r\n                    try {\r\n                        Write-Host \"[Info] Disabling screensaver.\"\r\n\r\n                        # Remove the screensaver registry key\r\n                        if ($currentScreensaver) {\r\n                            Write-Host \"[Info] Removing $regPath\\SCRNSAVE.EXE (current value: $currentScreensaver)\"\r\n                            Remove-ItemProperty -Path $regPath -Name \"SCRNSAVE.EXE\" -ErrorAction Stop\r\n                        }\r\n\r\n                        # Remove the password requirement registry key\r\n                        if ($currentScreenSaverIsSecure) {\r\n                            Write-Host \"[Info] Removing $regPath\\ScreenSaverIsSecure (current value: $currentScreenSaverIsSecure)\"\r\n                            Remove-ItemProperty -Path $regPath -Name \"ScreenSaverIsSecure\" -ErrorAction Stop\r\n                        }\r\n\r\n                        # Remove the screensaver timeout key\r\n                        if ($currentScreenSaverTimeout) {\r\n                            Write-Host \"[Info] Removing $regPath\\ScreenSaveTimeout (current value: $currentScreenSaverTimeout)\"\r\n                            Remove-ItemProperty -Path $regPath -Name \"ScreenSaveTimeout\" -ErrorAction Stop\r\n                        }\r\n\r\n                        Write-Host \"[Info] Successfully disabled screensaver.\"\r\n                    }\r\n                    catch {\r\n                        Write-Host \"[Error] Failed to disable screensaver.\"\r\n                        Write-Host \"$($_.Exception.Message)\"\r\n                        $ExitCode = 1\r\n                    }\r\n                }\r\n            }\r\n            else {\r\n                $screensaverFileName = $screensaverMap[$SelectScreensaver]\r\n\r\n                if ($currentScreensaver -eq \"$env:SystemRoot\\System32\\$screensaverFileName\") {\r\n                    Write-Host \"[Info] Screensaver is already set to '$SelectScreensaver'.\"\r\n                }\r\n                else {\r\n                    try {\r\n                        Write-Host \"[Info] Setting screensaver to '$SelectScreensaver'.\"\r\n                        Set-RegKey -Path $regPath -Name \"SCRNSAVE.EXE\" -Value \"$env:SystemRoot\\System32\\$screensaverFileName\" -PropertyType \"String\"\r\n                    }\r\n                    catch {\r\n                        Write-Host \"[Error] Failed to set screensaver.\"\r\n                        Write-Host \"$($_.Exception.Message)\"\r\n                        $ExitCode = 1\r\n                    }\r\n                }\r\n            }\r\n            Write-Host \"\"\r\n        }\r\n\r\n        # If set to skip all settings, continue to the next profile\r\n        # This will be true if the user selected 'None' as the screensaver\r\n        if ($SkipAllSettings) {\r\n            Write-Host \"[Info] Finished working on '$($UserProfile.Name)' profile.`n\"\r\n            continue\r\n        }\r\n\r\n        # Set screensaver timeout\r\n        if ($waitTime) {\r\n            # Get the current value\r\n            $currentValue = (Get-ItemProperty -Path $regPath -Name ScreenSaveTimeOut -ErrorAction SilentlyContinue).ScreenSaveTimeOut\r\n\r\n            # Check if it is already set, if not then set it\r\n            if ($currentValue -eq ($waitTime * 60)) {\r\n                Write-Host \"[Info] Screensaver timeout is already set to $waitTime minute(s).\"\r\n            }\r\n            else {\r\n                try {\r\n                    Write-Host \"[Info] Setting screensaver timeout to $waitTime minute(s).\"\r\n                    Set-RegKey -Path $regPath -Name ScreenSaveTimeOut -Value ($waitTime * 60) -PropertyType \"String\"\r\n                }\r\n                catch {\r\n                    Write-Host \"[Error] Failed to set screensaver timeout.\"\r\n                    Write-Host \"$($_.Exception.Message)\"\r\n                    $ExitCode = 1\r\n                }\r\n            }\r\n            Write-Host \"\"\r\n        }\r\n\r\n        # Get current value for password required on resume\r\n        $currentValue = (Get-ItemProperty -Path $regPath -Name ScreenSaverIsSecure -ErrorAction SilentlyContinue).ScreenSaverIsSecure\r\n\r\n        # Check if password required on resume is set, if not set it\r\n        if ($OnResumeEnterPassword) {\r\n            if ($currentValue -eq 1) {\r\n                Write-Host \"[Info] Screensaver password requirement is already enabled.\"\r\n            }\r\n            else {\r\n                try {\r\n                    Write-Host \"[Info] Enabling screensaver password requirement.\"\r\n                    Set-RegKey -Path $regPath -Name ScreenSaverIsSecure -Value 1 -PropertyType \"String\"\r\n                }\r\n                catch {\r\n                    Write-Host \"[Error] Failed to enable screensaver password requirement.\"\r\n                    Write-Host \"$($_.Exception.Message)\"\r\n                    $ExitCode = 1\r\n                }\r\n            }\r\n        }\r\n        else {\r\n            if ($currentValue -eq 0) {\r\n                Write-Host \"[Info] Screensaver password requirement is already disabled.\"\r\n            }\r\n            else {\r\n                try {\r\n                    Write-Host \"[Info] Disabling screensaver password requirement.\"\r\n                    Set-RegKey -Path $regPath -Name ScreenSaverIsSecure -Value 0 -PropertyType \"String\"\r\n                }\r\n                catch {\r\n                    Write-Host \"[Error] Failed to disable screensaver password requirement.\"\r\n                    Write-Host \"$($_.Exception.Message)\"\r\n                    $ExitCode = 1\r\n                }\r\n            }\r\n        }\r\n\r\n        # If using the default photos directory path, set the photos directory path to the user's Pictures folder\r\n        if ($defaultPhotosPath){\r\n            $PhotosDirectoryPath = \"$($UserProfile.Path)\\Pictures\"\r\n        }\r\n\r\n        # Set photos screensaver directory path\r\n        if ($SelectScreensaver -eq \"Photos\" -and $PhotosDirectoryPath){\r\n            Write-Host \"\"\r\n            # Photos screensaver uses a different registry key\r\n            $photosRegPath = \"Registry::HKEY_USERS\\$currentUserSID\\SOFTWARE\\Microsoft\\Windows Photo Viewer\\Slideshow\\Screensaver\"\r\n\r\n            # Convert the photos directory path to an EncryptedPIDL, which is what the registry expects\r\n            try {\r\n                $EncryptedPIDL = Get-EncryptedPIDLStringFromPath $PhotosDirectoryPath\r\n            }\r\n            catch {\r\n                Write-Host \"[Error] Error converting '$PhotosDirectoryPath' to EncryptedPIDL string.\"\r\n                Write-Host \"[Error] $($_.Exception.Message)\"\r\n                $EncryptedPIDL = $null\r\n                $ExitCode = 1\r\n            }\r\n\r\n            # Check if the registry path exists, create it if not\r\n            if (-not (Test-Path -Path $photosRegPath)) {\r\n                try {\r\n                    New-Item -Path $photosRegPath -Force -ErrorAction Stop | Out-Null\r\n                }\r\n                catch {\r\n                    Write-Host \"[Error] Error creating the registry path '$photosRegPath' for photos screensaver.\"\r\n                    Write-Host \"$($_.Exception.Message)\"\r\n                    $EncryptedPIDL = $null\r\n                    $ExitCode = 1\r\n                }\r\n            }\r\n\r\n            if ($EncryptedPIDL){\r\n                # Get the current value of the photos directory path\r\n                $currentValue = (Get-ItemProperty -Path $photosRegPath -Name \"EncryptedPIDL\" -ErrorAction SilentlyContinue).\"EncryptedPIDL\"\r\n\r\n                # If the current value is not null, try to convert it to a path for comparison\r\n                if ($currentValue){\r\n                    # Get the current value directory path\r\n                    try {\r\n                        # Trim the whitespace and remove null characters\r\n                        $currentValueDirectoryPath = (Convert-PIDLToPath $currentValue).Trim() -replace \"\\u0000\"\r\n                    }\r\n                    catch {\r\n                        Write-Host \"[Error] Error converting current PIDL value to path.\"\r\n                        Write-Host \"$($_.Exception.Message)\"\r\n                        $currentValueDirectoryPath = $null\r\n                        $ExitCode = 1\r\n                    }\r\n                }\r\n\r\n                # Check if it is already set, if not then set it\r\n                if ($currentValueDirectoryPath -eq $PhotosDirectoryPath) {\r\n                    Write-Host \"[Info] Photos screensaver is already using '$PhotosDirectoryPath'.\"\r\n                }\r\n                else {\r\n                    if ($currentValueDirectoryPath) {\r\n                        Write-Host \"[Info] Photos screensaver directory is currently using '$currentValueDirectoryPath'.\"\r\n                    }\r\n\r\n                    # Set the photos screensaver directory path\r\n                    try {\r\n                        Write-Host \"[Info] Setting photos screensaver to use '$PhotosDirectoryPath'.\"\r\n                        Set-ItemProperty -Path $photosRegPath -Name \"EncryptedPIDL\" -Value $EncryptedPIDL -Type \"String\" -Force -Confirm:$false -ErrorAction Stop\r\n                        Write-Host \"[Info] Successfully set photos screensaver to use '$PhotosDirectoryPath'.\"\r\n                    }\r\n                    catch {\r\n                        Write-Host \"[Error] Failed to set photos screensaver directory.\"\r\n                        Write-Host \"$($_.Exception.Message)\"\r\n                        $currentValue = $null\r\n                        $ExitCode = 1\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n        # Set 3D Text content\r\n        if ($SelectScreensaver -eq \"3D Text\" -and $textFor3DText) {\r\n            Write-Host \"\"\r\n\r\n            # 3D Text has a different registry path than the rest of the settings\r\n            $3DTextRegPath = \"Registry::HKEY_USERS\\$currentUserSID\\Software\\Microsoft\\Windows\\CurrentVersion\\Screensavers\\ssText3d\"\r\n\r\n            # Get the current value of the text\r\n            $currentValue = (Get-ItemProperty -Path $regPath -Name DisplayString -ErrorAction SilentlyContinue).DisplayString\r\n\r\n            # Check if it is already set, if not then set it\r\n            if ($currentValue -eq $textFor3DText) {\r\n                Write-Host \"[Info] 3D Text is already set to '$textFor3DText'.\"\r\n            }\r\n            else {\r\n                try {\r\n                    Write-Host \"[Info] Setting 3D Text to '$textFor3DText'.\"\r\n                    Set-RegKey -Path $3DTextRegPath -Name DisplayString -Value $textFor3DText -PropertyType \"String\"\r\n                }\r\n                catch {\r\n                    Write-Host \"[Error] Failed to set 3D Text.\"\r\n                    Write-Host \"$($_.Exception.Message)\"\r\n                    $ExitCode = 1\r\n                }\r\n            }\r\n        }\r\n        Write-Host \"`n[Info] Finished working on '$($UserProfile.Name)' profile.`n\"\r\n    }\r\n\r\n    # If user profiles were loaded, unload the profiles\r\n    if ($ProfileWasLoaded.Count -gt 0) {\r\n        foreach ($UserProfile in $ProfileWasLoaded) {\r\n            # Unload NTuser.dat\r\n            [gc]::Collect()\r\n            Start-Sleep 1\r\n            try {\r\n                Start-Process -FilePath \"cmd.exe\" -ArgumentList \"\/C reg.exe UNLOAD HKU\\$currentUserSID\" -Wait -WindowStyle Hidden -ErrorAction Stop | Out-Null\r\n            }\r\n            catch {\r\n                Write-Host \"[Error] Error unloading the profile for '$($UserProfile.Name)'.\"\r\n                Write-Host \"[Error] $($_.Exception.Message)\"\r\n                $ExitCode = 1\r\n            }\r\n        }\r\n    }\r\n\r\n     # if force reboot was selected, schedule a reboot in 1 minute and notify the user\r\n     if ($ForceReboot) {\r\n        Write-Host \"[Info] Rebooting computer in 60 seconds...\"\r\n        shutdown.exe -r -t 60\r\n    }\r\n    \r\n    exit $ExitCode\r\n}\r\nend {\r\n    \r\n    \r\n    \r\n}<\/pre>\n<p>&nbsp;<\/p>\n\n<h2>Description d\u00e9taill\u00e9e<\/h2>\n<p>Voici comment ce script accomplit sa t\u00e2che :<\/p>\n<ol>\n<li><strong>Contr\u00f4le des privil\u00e8ges<\/strong><strong><br \/>\n<\/strong>Le script v\u00e9rifie d&rsquo;abord s&rsquo;il est ex\u00e9cut\u00e9 avec des droits d&rsquo;administrateur. \u00c9tant donn\u00e9 que les modifications du registre pour d&rsquo;autres profils d&rsquo;utilisateurs requi\u00e8rent des privil\u00e8ges \u00e9lev\u00e9s, cette v\u00e9rification permet d&rsquo;\u00e9viter une ex\u00e9cution non autoris\u00e9e.<\/li>\n<li><strong>Param\u00e8tres d&rsquo;entr\u00e9e<\/strong>\n<ul>\n<li>SelectScreensaver : Choisissez parmi les options int\u00e9gr\u00e9es telles que \u201cBubbles,\u201d \u201cMystify,\u201d ou \u201c3D Text\u201d.<\/li>\n<li>WaitTime : D\u00e9finir la dur\u00e9e (en minutes) avant que l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran ne s&rsquo;active.<\/li>\n<li>OnResumeEnterPassword : Renforcer le mot de passe au r\u00e9veil.<\/li>\n<li>PhotosDirectoryPath : Chemin personnalis\u00e9 pour l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran Photos.<\/li>\n<li>TextFor3DText : D\u00e9finir un texte personnalis\u00e9 pour l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran 3D Text.<\/li>\n<li>ForceReboot : Red\u00e9marrer \u00e9ventuellement apr\u00e8s les modifications.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Validation et cartographie des \u00e9crans de veille<\/strong><strong><br \/>\n<\/strong>Une table de hachage associe des noms d&rsquo;\u00e9conomiseurs d&rsquo;\u00e9cran conviviaux \u00e0 leurs fichiers ex\u00e9cutables (par exemple, Mystify \u2192 Mystify.scr).<\/li>\n<li><strong>Modifications des cl\u00e9s de registre<\/strong><strong><br \/>\n<\/strong>Il utilise la fonction d&rsquo;aide Set-RegKey pour mettre \u00e0 jour ou cr\u00e9er les cl\u00e9s de registre n\u00e9cessaires sous HKEY_USERS pour chaque SID d&rsquo;utilisateur.<\/li>\n<li><strong>Traitement des profils d&rsquo;utilisateurs<\/strong><strong><br \/>\n<\/strong>Via Get-UserHives, il charge NTUSER.DAT pour chaque utilisateur s&rsquo;il n&rsquo;est pas d\u00e9j\u00e0 charg\u00e9, rendant leurs ruches (hives) de registre temporairement accessibles.<\/li>\n<li><strong>Param\u00e8tres sp\u00e9cifiques en fonction de l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran<\/strong>\n<ul>\n<li><strong>None<\/strong> : Supprime les touches pertinentes pour d\u00e9sactiver l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran.<\/li>\n<li><strong>Photos<\/strong> : Encode le chemin de la photo en une cha\u00eene PIDL Base64.<\/li>\n<li><strong>3D Text<\/strong> : D\u00e9finit la valeur de la cha\u00eene d&rsquo;affichage de l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran.<\/li>\n<\/ul>\n<\/li>\n<li><strong>D\u00e9charger les profils<\/strong><strong><br \/>\n<\/strong>Les profils charg\u00e9s au moment de l&rsquo;ex\u00e9cution sont d\u00e9charg\u00e9s en toute s\u00e9curit\u00e9 afin d&rsquo;\u00e9viter de laisser des ruches de registre mont\u00e9es.<\/li>\n<li><strong>Red\u00e9marrage facultatif<\/strong><strong><br \/>\n<\/strong>Si l&rsquo;option -ForceReboot est utilis\u00e9e, elle planifie un red\u00e9marrage du syst\u00e8me au bout de 60 secondes.<\/li>\n<\/ol>\n<h2>Cas d&rsquo;utilisation potentiels<\/h2>\n<h3>\u00c9tude de cas\u00a0: Application de la conformit\u00e9 d&rsquo;entreprise<\/h3>\n<p>Une entreprise MSP g\u00e9rant des appareils pour un client du secteur de la sant\u00e9 doit impl\u00e9menter un verrouillage automatique de l&rsquo;\u00e9cran apr\u00e8s 5 minutes d&rsquo;inactivit\u00e9 avec une protection par mot de passe activ\u00e9e. \u00c0 l&rsquo;aide de ce script, l&rsquo;administrateur peut mettre en place une strat\u00e9gie avec :<\/p>\n<p>powershell<\/p>\n<p>CopyEdit<\/p>\n<p>-SelectScreensaver \u00ab\u00a0Blank\u00a0\u00bb -WaitTime 5 -OnResumeEnterPassword:$true -ForceReboot<\/p>\n<p>Cette commande unique permet de mettre \u00e0 jour tous les profils d&rsquo;utilisateurs sur un appareil donn\u00e9 sans avoir recours \u00e0 la strat\u00e9gie de groupe ou \u00e0 des solutions bas\u00e9es sur le domaine.<\/p>\n<h2>Comparaisons<\/h2>\n<h3>Strat\u00e9gie de groupe et script PowerShell<\/h3>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: center;\"><strong>Fonction<\/strong><\/td>\n<td style=\"text-align: center;\"><strong>Strat\u00e9gie de groupe<\/strong><\/td>\n<td style=\"text-align: center;\"><strong>Ce script PowerShell<\/strong><\/td>\n<\/tr>\n<tr>\n<td>Domaine requis<\/td>\n<td>\u2705 Oui<\/td>\n<td>\u274c Non<\/td>\n<\/tr>\n<tr>\n<td>Cibler tous les utilisateurs<\/td>\n<td>\u2705 Oui<\/td>\n<td>\u2705 Oui<\/td>\n<\/tr>\n<tr>\n<td>Chemins d&rsquo;acc\u00e8s personnalis\u00e9s\/texte<\/td>\n<td>\u274c Limit\u00e9e<\/td>\n<td>\u2705 Contr\u00f4le total<\/td>\n<\/tr>\n<tr>\n<td>Prise en charge des terminaux hors ligne<\/td>\n<td>\u274c Non<\/td>\n<td>\u2705 Oui<\/td>\n<\/tr>\n<tr>\n<td>Application en temps r\u00e9el<\/td>\n<td>\u274c Non (n\u00e9cessite une actualisation)<\/td>\n<td>\u2705 Imm\u00e9diate (avec red\u00e9marrage si n\u00e9cessaire)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Pour les MSP qui g\u00e8rent des environnements hybrides ou BYOD, ce script offre une flexibilit\u00e9 que les strat\u00e9gies de groupe (GPO) n&rsquo;ont pas.<\/p>\n<h2>FAQ<\/h2>\n<h3>Q\u00a0: Puis-je utiliser ce script sur des machines n&rsquo;appartenant pas \u00e0 un domaine ?<\/h3>\n<p>Oui. Le script fonctionne ind\u00e9pendamment de l&rsquo;appartenance \u00e0 un domaine.<\/p>\n<h3>Q\u00a0: Que se passe-t-il si l&rsquo;utilisateur est d\u00e9j\u00e0 connect\u00e9 ?<\/h3>\n<p>Les modifications s&rsquo;appliquent, mais peuvent n\u00e9cessiter une d\u00e9connexion ou un red\u00e9marrage pour \u00eatre pleinement prises en compte, \u00e0 moins que l&rsquo;option -ForceReboot ne soit utilis\u00e9e.<\/p>\n<h3>Q\u00a0: Fonctionnera-t-il avec Windows 11 ?<\/h3>\n<p>Oui, \u00e0 condition que le syst\u00e8me d&rsquo;exploitation prenne en charge les fichiers binaires et les chemins d&rsquo;acc\u00e8s au registre de l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran s\u00e9lectionn\u00e9.<\/p>\n<h3>Q\u00a0: Que se passe-t-il si je fournis un chemin d&rsquo;acc\u00e8s r\u00e9seau pour les photos ?<\/h3>\n<p>Le script refuse les chemins UNC pour l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran Photos, qui doit utiliser un r\u00e9pertoire local.<\/p>\n<h2>Implications<\/h2>\n<p>Une mauvaise configuration de l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran peut rendre les terminaux vuln\u00e9rables, soit en ne verrouillant pas les sessions inactives, soit en activant des effets visuels g\u00eanants. Ce script ne se contente pas d&rsquo;assurer la conformit\u00e9, il favorise \u00e9galement\u00a0<strong>l&rsquo;hygi\u00e8ne de s\u00e9curit\u00e9 de l&rsquo;utilisateur<\/strong>. Il emp\u00eache l&rsquo;exposition accidentelle de donn\u00e9es sensibles et garantit un comportement coh\u00e9rent entre les comptes d&rsquo;utilisateurs, ce qui est essentiel dans les environnements d&rsquo;appareils partag\u00e9s.<\/p>\n<h2>Recommandations<\/h2>\n<ul>\n<li><strong>Ex\u00e9cutez en tant qu&rsquo;administrateur<\/strong>\u00a0: Ex\u00e9cutez toujours le script avec des autorisations \u00e9lev\u00e9es.<\/li>\n<li><strong>Utilisez\u00a0<\/strong><strong>-ForceReboot<\/strong><strong>\u00a0dans les d\u00e9ploiements critiques<\/strong> : Assure l&rsquo;application de tous les param\u00e8tres sans d\u00e9pendre de la d\u00e9connexion des utilisateurs.<\/li>\n<li><strong>Pr\u00e9-test sur une machine d&rsquo;essai<\/strong> : Valider les chemins d&rsquo;acc\u00e8s, en particulier pour les photos et les \u00e9crans de veille en 3D.<\/li>\n<li><strong>Documentez les param\u00e8tres dans les outils RMM<\/strong> : Lors du d\u00e9ploiement via des syst\u00e8mes tels que NinjaOne, \u00e9tiquetez clairement les param\u00e8tres en vue d&rsquo;une maintenance ult\u00e9rieure.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>La gestion de l&rsquo;exp\u00e9rience utilisateur et de la conformit\u00e9 sur les terminaux n&rsquo;a pas besoin d&rsquo;impliquer des strat\u00e9gies de groupe (GPO) ou des \u00e9tapes manuelles fastidieuses. Ce script PowerShell permettant de modifier les param\u00e8tres de l&rsquo;\u00e9conomiseur d&rsquo;\u00e9cran simplifie l&rsquo;application des strat\u00e9gies et facilite la gestion de tous les profils d&rsquo;utilisateurs sur un appareil Windows. Lorsqu&rsquo;il est int\u00e9gr\u00e9 dans un \u00e9cosyst\u00e8me d&rsquo;automatisation plus large comme\u00a0<a href=\"https:\/\/www.ninjaone.com\/fr\/\"><strong>NinjaOne<\/strong><\/a> vous pouvez d\u00e9ployer ce script de mani\u00e8re optimale sur des flottes de machines, suivre l&rsquo;\u00e9tat d&rsquo;ex\u00e9cution et l&rsquo;int\u00e9grer \u00e0 d&rsquo;autres scripts afin de garder le contr\u00f4le total de votre environnement.<\/p>\n","protected":false},"author":35,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_lmt_disableupdate":"no","_lmt_disable":""},"operating_system":[4212],"use_cases":[4281],"class_list":["post-530395","script_hub","type-script_hub","status-publish","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub\/530395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/comments?post=530395"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media?parent=530395"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/operating_system?post=530395"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/use_cases?post=530395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}