cschneegans / unattend-generator

.NET Core library to create highly customized autounattend.xml files
https://schneegans.de/windows/unattend-generator/
MIT License
680 stars 62 forks source link

Properly escape vertical slashes in reg files #76

Closed hoang-himself closed 1 month ago

hoang-himself commented 1 month ago

When using powershell in reg, the vertical slash is not properly escaped

reg.exe add "HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "UninstallCopilot" /t REG_SZ /d "powershell.exe -NoProfile -Command \"Get-AppxPackage -Name 'Microsoft.Windows.Ai.Copilot.Provider' | Remove-AppxPackage;\"" /f

The vertical slash should be escaped as ^|

reg.exe add "HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "UninstallCopilot" /t REG_SZ /d "powershell.exe -NoProfile -Command \"Get-AppxPackage -Name 'Microsoft.Windows.Ai.Copilot.Provider' ^| Remove-AppxPackage;\"" /f

This one can be hotfixed

https://github.com/cschneegans/unattend-generator/blob/7a577e15c56c859b83825d4d00eafcaa862a28c3/modifier/Bloatware.cs#L201

This will require further testing

https://github.com/cschneegans/unattend-generator/blob/7a577e15c56c859b83825d4d00eafcaa862a28c3/modifier/Optimizations.cs#L117-L119

https://github.com/cschneegans/unattend-generator/blob/7a577e15c56c859b83825d4d00eafcaa862a28c3/Main.cs#L223-L226

cschneegans commented 1 month ago

^ is the escape character for cmd.exe, and the commands from <RunSynchronousCommand> elements are not run by cmd.exe. If you want to test these commands, use the Run dialog (Windows key+R).