Code: @echo off setlocal enabledelayedexpansion chcp 65001 >nul set "input=%*" if "%input%"=="" ( echo Usage: SetDefaultUserFolder.cmd ^<value^> echo Example: SetDefaultUserFolder.cmd MyFolderName exit /b 1 ) :: Now call PowerShell for detailed Unicode and reserved name validation powershell -NoProfile -Command ^ "$name = '%input%'.Trim();" ^ "$invalid = [System.IO.Path]::GetInvalidFileNameChars() + @('@', '.', ';', '=', ',', '+');" ^ "if ([string]::IsNullOrWhiteSpace($name)) { Write-Host '[ERROR] Name is empty or whitespace.'; exit 1 }" ^ "elseif ($name.Length -gt 16) { Write-Host '[ERROR] Name exceeds 16 character limit.'; exit 2 }" ^ "elseif ($name.EndsWith(' ') -or $name.EndsWith('.')) { Write-Host '[ERROR] Name cannot end with space or dot.'; exit 1 }" ^ "elseif ('CON','PRN','AUX','NUL','COM1','COM2','COM3','COM4','COM5','COM6','COM7','COM8','COM9','LPT1','LPT2','LPT3','LPT4','LPT5','LPT6','LPT7','LPT8','LPT9' -contains $name.ToUpper()) { Write-Host \"[ERROR] '$name' is a reserved name.\"; exit 1 }" ^ "elseif ($invalidChar = $name.ToCharArray() | Where-Object { $invalid -contains $_ } | Select-Object -First 1) { Write-Host \"[ERROR] Invalid character found in name: '$invalidChar'\"; exit 1 }" ^ "else { Write-Host \"[OK] '$name' is a valid folder name.\" }" if errorlevel 1 ( echo [ERROR] Folder name validation failed in PowerShell. exit /b 4 ) :: Write to registry reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\UserOOBE /v SetSAMFolderName /t REG_SZ /d "%input%" /f >nul if %errorlevel% EQU 0 ( echo [SUCCESS] Default user folder set to: %input% ) else ( echo [ERROR] Failed to set registry value. %errorlevel% exit /b 5 ) exit /b 0
Why enabledelayedexpansion if you don't intend to use it? "%input%" comparison might fail if it contains invalid characters
Exactly! Hence, why I asked how can one have sharp edges? Also, how can one have multiple town weather forecasts (live tiles) on the start menu like on W10? Is that possible on W11?
Are they still allowing interns to write PS code? -contains is case-insensitive, so why bother with $name.ToUpper() ?