cschneegans / unattend-generator

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

Issue for Running as CMD script in "Scripts to run whenever a user logs on for the first time" Section #85

Open icristi2 opened 5 days ago

icristi2 commented 5 days ago

When I copy my CMD lines for execution to "Scripts to run whenever a user logs on for the first time" section they get executed as powershell and not as batch. I can even see the PS window as opposed to the CMD one I could previously view. Tried to put the code in every box 1, 2, 3,and 4 and manually select "as a .cmd file." but the result is the same and gets executed as PS. For .reg is OK, as I have a regkey that I also put in "Scripts to run whenever a user logs on for the first time" and sets "Visual Effects" to some custom settings and it gets applied on my test OS without any issue, as before.

The autounattended.xml generator had no such issues approx. 2 week ago when I created an .xml and tested with same OS and same environment. Maybe it's related somehow to latest feature additions? I noticed some new features added lately.

cschneegans commented 5 days ago

Your observation is correct, but this is the intended behavior, which was introduced via https://github.com/cschneegans/unattend-generator/commit/dcf3ea46feb5aa82b562c4531f1a4475f57ce0bf.

Previously, you might have seen multiple windows popping up when a user logs on for the first time. All RunOnce commands (including those provided by custom scripts) are now run from a single PowerShell process. Furthermore, output from these commands is collected in %TEMP%\UserOnce.log for debugging purposes.

.reg and .cmd custom scripts are still properly executed, and your autounattend.xml file will contain elements like these:

<RunSynchronousCommand wcm:action="add">
  <Order>…</Order>
  <Path>reg.exe load "HKU\DefaultUser" "C:\Users\Default\NTUSER.DAT"</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
  <Order>…</Order>
  <Path>reg.exe add "HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "UnattendedSetup" /t REG_SZ /d "powershell.exe -NoProfile -Command \"Get-Content -LiteralPath 'C:\Windows\Setup\Scripts\UserOnce.ps1' -Raw | Invoke-Expression;\"" /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
  <Order>…</Order>
  <Path>reg.exe unload "HKU\DefaultUser"</Path>
</RunSynchronousCommand>
<File path="C:\Windows\Setup\Scripts\UserOnce.ps1">
  &amp; {
    Get-Content -LiteralPath 'C:\Windows\Setup\Scripts\SetColorTheme.ps1' -Raw | Invoke-Expression;
    Get-Content -LiteralPath 'C:\Windows\Setup\Scripts\SetWallpaper.ps1' -Raw | Invoke-Expression;
    reg.exe import "C:\Windows\Setup\Scripts\unattend-01.reg";
    C:\Windows\Setup\Scripts\unattend-02.cmd;
  } *&gt;&amp;1 &gt;&gt; "$env:TEMP\UserOnce.log";
</File>