Pcgamer27

Member
Joined
Mar 1, 2025
Messages
65
Hello I have a question I am looking for a script to create a recovery partition to put in an autounattend file
 

To create a recovery partition as part of an unattended (autounattend.xml) installation for Windows 11, you'll want to use the DiskConfiguration and CreatePartitions components in your answer file. This instructs Windows Setup to prepare a custom disk layout—including a dedicated recovery partition.
Below is an example snippet you can adapt and place in the <DiskConfiguration> section of your autounattend.xml. You can then use Windows System Image Manager (SIM) or tools like DISMTools to generate/test the full answer file and ensure validity.

Example: autounattend.xml Recovery Partition Script​

Code:
<DiskConfiguration>
  <WillShowUI>OnError</WillShowUI>
  <Disk wcm:action="add">
    <DiskID>0</DiskID> <!-- Usually the main system disk -->
    <WillWipeDisk>true</WillWipeDisk>
    <!-- EFI System Partition -->
    <CreatePartitions>
      <CreatePartition wcm:action="add">
        <Order>1</Order>
        <Type>EFI</Type>
        <Size>100</Size> <!-- Size in MB -->
      </CreatePartition>
      <!-- Microsoft Reserved Partition -->
      <CreatePartition wcm:action="add">
        <Order>2</Order>
        <Type>MSR</Type>
        <Size>16</Size>
      </CreatePartition>
      <!-- Windows Partition -->
      <CreatePartition wcm:action="add">
        <Order>3</Order>
        <Type>Primary</Type>
        <Extend>true</Extend>
      </CreatePartition>
      <!-- Recovery Partition -->
      <CreatePartition wcm:action="add">
        <Order>4</Order>
        <Type>Primary</Type>
        <Size>1000</Size> <!-- Size in MB: 1GB (adjust as needed) -->
      </CreatePartition>
    </CreatePartitions>
    <ModifyPartitions>
      <!-- Set the Windows partition properties -->
      <ModifyPartition wcm:action="add">
        <Order>3</Order>
        <PartitionID>3</PartitionID>
        <Format>NTFS</Format>
        <Letter>C</Letter>
        <Label>Windows</Label>
        <Active>true</Active>
      </ModifyPartition>
      <!-- Set the Recovery partition properties -->
      <ModifyPartition wcm:action="add">
        <Order>4</Order>
        <PartitionID>4</PartitionID>
        <Format>NTFS</Format>
        <Label>Recovery</Label>
        <TypeID>DE94BBA4-06D1-4D40-A16A-BFD50179D6AC</TypeID>
      </ModifyPartition>
    </ModifyPartitions>
  </Disk>
</DiskConfiguration>

Key Notes:​

  • The GUID DE94BBA4-06D1-4D40-A16A-BFD50179D6AC marks the partition for WinRE/Recovery ("Windows Recovery Environment").
  • The <Extend>true</Extend> directive fills available space except for reserved/recovery partitions.
  • You may need a later step (e.g., with a post-setup script) to copy the actual winre.wim file and register it with reagentc /setreimage. Windows Setup usually takes care of WinRE automatically, but custom builds may require manual touch-up.
  • Integrate this block into your full autounattend.xml under the windowsPE pass.

See Also:​

  • Automated tools like DISMTools can generate this disk layout via a guided wizard if you’re not comfortable editing XML manually.
If you need the rest of the answer file template, or a script to register WinRE after install, just ask!
 

To create a recovery partition as part of an unattended (autounattend.xml) installation for Windows 11, you'll want to use the DiskConfiguration and CreatePartitions components in your answer file. This instructs Windows Setup to prepare a custom disk layout—including a dedicated recovery partition.
Below is an example snippet you can adapt and place in the <DiskConfiguration> section of your autounattend.xml. You can then use Windows System Image Manager (SIM) or tools like DISMTools to generate/test the full answer file and ensure validity.

Example: autounattend.xml Recovery Partition Script​

Code:
<DiskConfiguration>
  <WillShowUI>OnError</WillShowUI>
  <Disk wcm:action="add">
    <DiskID>0</DiskID> <!-- Usually the main system disk -->
    <WillWipeDisk>true</WillWipeDisk>
    <!-- EFI System Partition -->
    <CreatePartitions>
      <CreatePartition wcm:action="add">
        <Order>1</Order>
        <Type>EFI</Type>
        <Size>100</Size> <!-- Size in MB -->
      </CreatePartition>
      <!-- Microsoft Reserved Partition -->
      <CreatePartition wcm:action="add">
        <Order>2</Order>
        <Type>MSR</Type>
        <Size>16</Size>
      </CreatePartition>
      <!-- Windows Partition -->
      <CreatePartition wcm:action="add">
        <Order>3</Order>
        <Type>Primary</Type>
        <Extend>true</Extend>
      </CreatePartition>
      <!-- Recovery Partition -->
      <CreatePartition wcm:action="add">
        <Order>4</Order>
        <Type>Primary</Type>
        <Size>1000</Size> <!-- Size in MB: 1GB (adjust as needed) -->
      </CreatePartition>
    </CreatePartitions>
    <ModifyPartitions>
      <!-- Set the Windows partition properties -->
      <ModifyPartition wcm:action="add">
        <Order>3</Order>
        <PartitionID>3</PartitionID>
        <Format>NTFS</Format>
        <Letter>C</Letter>
        <Label>Windows</Label>
        <Active>true</Active>
      </ModifyPartition>
      <!-- Set the Recovery partition properties -->
      <ModifyPartition wcm:action="add">
        <Order>4</Order>
        <PartitionID>4</PartitionID>
        <Format>NTFS</Format>
        <Label>Recovery</Label>
        <TypeID>DE94BBA4-06D1-4D40-A16A-BFD50179D6AC</TypeID>
      </ModifyPartition>
    </ModifyPartitions>
  </Disk>
</DiskConfiguration>

Key Notes:​

  • The GUID DE94BBA4-06D1-4D40-A16A-BFD50179D6AC marks the partition for WinRE/Recovery ("Windows Recovery Environment").
  • The <Extend>true</Extend> directive fills available space except for reserved/recovery partitions.
  • You may need a later step (e.g., with a post-setup script) to copy the actual winre.wim file and register it with reagentc /setreimage. Windows Setup usually takes care of WinRE automatically, but custom builds may require manual touch-up.
  • Integrate this block into your full autounattend.xml under the windowsPE pass.

See Also:​

  • Automated tools like DISMTools can generate this disk layout via a guided wizard if you’re not comfortable editing XML manually.
If you need the rest of the answer file template, or a script to register WinRE after install, just ask!

i need a reg or cmd to put on autounattend site
 

Attachments

  • Screenshot 2025-05-18 at 19.25.54.webp
    Screenshot 2025-05-18 at 19.25.54.webp
    24.6 KB · Views: 0
To register the Windows Recovery Environment (WinRE) after Windows installation (for example, in an autounattend post-setup phase), you typically use a command (CMD) rather than a registry edit. The process is:
  1. Ensure winre.wim exists (usually at C:\Windows\System32\Recovery\Winre.wim).
  2. Register the recovery image using:
    Code:
    reagentc /setreimage /path C:\Recovery\WindowsRE
    reagentc /enable
In your autounattend.xml, you can have this run automatically via <FirstLogonCommands> or <RunSynchronous> in OOBE or specialize pass, like so:
Code:
<FirstLogonCommands>
  <SynchronousCommand wcm:action="add">
    <Order>1</Order>
    <CommandLine>cmd /c mkdir C:\Recovery\WindowsRE</CommandLine>
    <Description>Create Recovery Folder</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>2</Order>
    <CommandLine>cmd /c copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim</CommandLine>
    <Description>Copy WinRE</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>3</Order>
    <CommandLine>cmd /c reagentc /setreimage /path C:\Recovery\WindowsRE</CommandLine>
    <Description>Register WinRE</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>4</Order>
    <CommandLine>cmd /c reagentc /enable</CommandLine>
    <Description>Enable WinRE</Description>
  </SynchronousCommand>
</FirstLogonCommands>
Key Details:
  • No registry hack is required: reagentc configures all necessary values.
  • WinRE will be enabled for recovery operations if the partition and WIM exist.
If you want a pure CMD script (to run afterward, or by SetupComplete.cmd), here is a single snippet:
Code:
md C:\Recovery\WindowsRE
copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim
reagentc /setreimage /path C:\Recovery\WindowsRE
reagentc /enable
Place this in a batch file (e.g., SetupComplete.cmd or as a synchronous command in the answer file post-install pass).
Let me know if you need the exact <RunSynchronous> example for the specialize pass or want details for applying this on custom partition paths!
 

To register the Windows Recovery Environment (WinRE) after Windows installation (for example, in an autounattend post-setup phase), you typically use a command (CMD) rather than a registry edit. The process is:
  1. Ensure winre.wim exists (usually at C:\Windows\System32\Recovery\Winre.wim).
  2. Register the recovery image using:
    Code:
    reagentc /setreimage /path C:\Recovery\WindowsRE
    reagentc /enable
In your autounattend.xml, you can have this run automatically via <FirstLogonCommands> or <RunSynchronous> in OOBE or specialize pass, like so:
Code:
<FirstLogonCommands>
  <SynchronousCommand wcm:action="add">
    <Order>1</Order>
    <CommandLine>cmd /c mkdir C:\Recovery\WindowsRE</CommandLine>
    <Description>Create Recovery Folder</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>2</Order>
    <CommandLine>cmd /c copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim</CommandLine>
    <Description>Copy WinRE</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>3</Order>
    <CommandLine>cmd /c reagentc /setreimage /path C:\Recovery\WindowsRE</CommandLine>
    <Description>Register WinRE</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>4</Order>
    <CommandLine>cmd /c reagentc /enable</CommandLine>
    <Description>Enable WinRE</Description>
  </SynchronousCommand>
</FirstLogonCommands>
Key Details:
  • No registry hack is required: reagentc configures all necessary values.
  • WinRE will be enabled for recovery operations if the partition and WIM exist.
If you want a pure CMD script (to run afterward, or by SetupComplete.cmd), here is a single snippet:
Code:
md C:\Recovery\WindowsRE
copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim
reagentc /setreimage /path C:\Recovery\WindowsRE
reagentc /enable
Place this in a batch file (e.g., SetupComplete.cmd or as a synchronous command in the answer file post-install pass).
Let me know if you need the exact <RunSynchronous> example for the specialize pass or want details for applying this on custom partition paths!

do you mean this way first login both script in cmd
 

Attachments

  • Screenshot 2025-05-18 at 19.41.43.webp
    Screenshot 2025-05-18 at 19.41.43.webp
    44.5 KB · Views: 0
Yes, that's correct! You can run both the WinRE registration script and the full system image backup script at first login (using <FirstLogonCommands> in your autounattend.xml) or place the commands inside a batch script (SetupComplete.cmd) to have everything happen automatically after Windows setup completes.

Example: Both Scripts in First Logon (autounattend.xml)​

Code:
<FirstLogonCommands>
  <SynchronousCommand wcm:action="add">
    <Order>1</Order>
    <CommandLine>cmd /c mkdir C:\Recovery\WindowsRE</CommandLine>
    <Description>Create Recovery Folder</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>2</Order>
    <CommandLine>cmd /c copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim</CommandLine>
    <Description>Copy WinRE Image</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>3</Order>
    <CommandLine>cmd /c reagentc /setreimage /path C:\Recovery\WindowsRE</CommandLine>
    <Description>Register WinRE</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>4</Order>
    <CommandLine>cmd /c reagentc /enable</CommandLine>
    <Description>Enable WinRE</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>5</Order>
    <CommandLine>wbadmin start backup -backupTarget:D: -allCritical -quiet</CommandLine>
    <Description>Full System Backup</Description>
  </SynchronousCommand>
</FirstLogonCommands>
  • This will:
    1. Prepare and populate the recovery folder
    2. Register and enable WinRE
    3. Trigger a full system image backup to D: (make sure the drive exists and has space!)

Alternative: Place Both Scripts in SetupComplete.cmd

If you use a batch file (e.g., C:\Windows\Setup\Scripts\SetupComplete.cmd):
Code:
[USER=35331]@echo[/USER] off
md C:\Recovery\WindowsRE
copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim
reagentc /setreimage /path C:\Recovery\WindowsRE
reagentc /enable
wbadmin start backup -backupTarget:D: -allCritical -quiet

Either method works—it’s just a matter of which phase of unattended setup you prefer.
If you want these commands as a single .cmd file, you can copy/paste them straight into a batch file to use with SetupComplete.cmd or call from <FirstLogonCommands>. Make sure your backup destination is valid before automated backup!
Let me know if you need these adjusted for a network drive, specific partition ID, or for the <RunSynchronous> block in the specialize pass.
 

Yes, that's correct! You can run both the WinRE registration script and the full system image backup script at first login (using <FirstLogonCommands> in your autounattend.xml) or place the commands inside a batch script (SetupComplete.cmd) to have everything happen automatically after Windows setup completes.

Example: Both Scripts in First Logon (autounattend.xml)​

Code:
<FirstLogonCommands>
  <SynchronousCommand wcm:action="add">
    <Order>1</Order>
    <CommandLine>cmd /c mkdir C:\Recovery\WindowsRE</CommandLine>
    <Description>Create Recovery Folder</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>2</Order>
    <CommandLine>cmd /c copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim</CommandLine>
    <Description>Copy WinRE Image</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>3</Order>
    <CommandLine>cmd /c reagentc /setreimage /path C:\Recovery\WindowsRE</CommandLine>
    <Description>Register WinRE</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>4</Order>
    <CommandLine>cmd /c reagentc /enable</CommandLine>
    <Description>Enable WinRE</Description>
  </SynchronousCommand>
  <SynchronousCommand wcm:action="add">
    <Order>5</Order>
    <CommandLine>wbadmin start backup -backupTarget:D: -allCritical -quiet</CommandLine>
    <Description>Full System Backup</Description>
  </SynchronousCommand>
</FirstLogonCommands>
  • This will:
    1. Prepare and populate the recovery folder
    2. Register and enable WinRE
    3. Trigger a full system image backup to D: (make sure the drive exists and has space!)

Alternative: Place Both Scripts in SetupComplete.cmd

If you use a batch file (e.g., C:\Windows\Setup\Scripts\SetupComplete.cmd):
Code:
[USER=35331]@echo[/USER] off
md C:\Recovery\WindowsRE
copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim
reagentc /setreimage /path C:\Recovery\WindowsRE
reagentc /enable
wbadmin start backup -backupTarget:D: -allCritical -quiet

Either method works—it’s just a matter of which phase of unattended setup you prefer.
If you want these commands as a single .cmd file, you can copy/paste them straight into a batch file to use with SetupComplete.cmd or call from <FirstLogonCommands>. Make sure your backup destination is valid before automated backup!
Let me know if you need these adjusted for a network drive, specific partition ID, or for the <RunSynchronous> block in the specialize pass.

i tried and it doesn't work the script stop working
 

If the script is stopping or failing when run during Windows Setup (via FirstLogonCommands or SetupComplete.cmd), here are the most common reasons and troubleshooting steps:

1. Permissions & Timing

  • Some commands (especially wbadmin and reagentc) require elevated permissions or may not work at the very first logon if the system isn’t fully set up yet.
  • SetupComplete.cmd runs as SYSTEM and is generally best for automation, but certain drives or services may not be available immediately after OOBE.

2. Common Script Issues

  • Target drive (D:) is missing or empty: If wbadmin cannot find D: or if it doesn’t have enough space, it will fail and may hang the script.
  • WinRE image missing or in use: If winre.wim isn't present, copy or reagentc will error out.
  • Syntax problems: Some commands need full paths, and you may need to use call or start for certain steps.

3. Logging for Troubleshooting

  • Add logging to your batch file to check exactly where it fails:
    Code:
    [USER=35331]@echo[/USER] off
    set LOGFILE=C:\setup_log.txt
    echo Starting Recovery and Backup > %LOGFILE%
    
    echo Creating recovery folder... >> %LOGFILE%
    md C:\Recovery\WindowsRE >> %LOGFILE% 2>&1
    
    echo Copying winre.wim... >> %LOGFILE%
    copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim >> %LOGFILE% 2>&1
    
    echo Setting WinRE image... >> %LOGFILE%
    reagentc /setreimage /path C:\Recovery\WindowsRE >> %LOGFILE% 2>&1
    
    echo Enabling WinRE... >> %LOGFILE%
    reagentc /enable >> %LOGFILE% 2>&1
    
    echo Starting WBAdmin backup... >> %LOGFILE%
    wbadmin start backup -backupTarget:D: -allCritical -quiet >> %LOGFILE% 2>&1
    
    echo Done! >> %LOGFILE%
  • This will create C:\setup_log.txt, which you can check after the install for errors.

4. Running Interactive Tools Like WBADMIN

  • wbadmin can fail if run from OOBE or very early first logon, especially if Shadow Copy services are not fully functional yet, or the target disk is not writable.

Alternatives:

  • Test running the script manually after setup completes (as admin) to see if it runs without issues.
  • Delay backup until setup is 100% complete, e.g., via Task Scheduler with a delay.

Network or Removable Storage?

  • If targeting a network share, map it first:
    Code:
    net use Z: \\server\backupshare /user:username password
    wbadmin start backup -backupTarget:Z: -allCritical -quiet

5. SetupComplete.cmd Specifics

  • Do not require user interaction. If any scripted command stops and waits for a prompt, the entire setup hangs.
  • No GUI/output is shown.

6. Testing and Isolation

  • Try running each line individually in a command prompt after the OS is set up.
  • Check paths for winre.wim and make sure your backup target (D: or network share) exists and is writeable.

Recommendations:​

  • Post your log file or error message here for precise troubleshooting.
  • If you’re working from a specific deployment, let me know which Windows version and what your drive layout looks like.
In summary:
Add logging, isolate which command fails, check the state of all needed files/folders/targets, and confirm all paths. Post any error output for help on that exact step!
 

If the script is stopping or failing when run during Windows Setup (via FirstLogonCommands or SetupComplete.cmd), here are the most common reasons and troubleshooting steps:

1. Permissions & Timing

  • Some commands (especially wbadmin and reagentc) require elevated permissions or may not work at the very first logon if the system isn’t fully set up yet.
  • SetupComplete.cmd runs as SYSTEM and is generally best for automation, but certain drives or services may not be available immediately after OOBE.

2. Common Script Issues

  • Target drive (D:) is missing or empty: If wbadmin cannot find D: or if it doesn’t have enough space, it will fail and may hang the script.
  • WinRE image missing or in use: If winre.wim isn't present, copy or reagentc will error out.
  • Syntax problems: Some commands need full paths, and you may need to use call or start for certain steps.

3. Logging for Troubleshooting

  • Add logging to your batch file to check exactly where it fails:
    Code:
    [USER=35331]@echo[/USER] off
    set LOGFILE=C:\setup_log.txt
    echo Starting Recovery and Backup > %LOGFILE%
    
    echo Creating recovery folder... >> %LOGFILE%
    md C:\Recovery\WindowsRE >> %LOGFILE% 2>&1
    
    echo Copying winre.wim... >> %LOGFILE%
    copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim >> %LOGFILE% 2>&1
    
    echo Setting WinRE image... >> %LOGFILE%
    reagentc /setreimage /path C:\Recovery\WindowsRE >> %LOGFILE% 2>&1
    
    echo Enabling WinRE... >> %LOGFILE%
    reagentc /enable >> %LOGFILE% 2>&1
    
    echo Starting WBAdmin backup... >> %LOGFILE%
    wbadmin start backup -backupTarget:D: -allCritical -quiet >> %LOGFILE% 2>&1
    
    echo Done! >> %LOGFILE%
  • This will create C:\setup_log.txt, which you can check after the install for errors.

4. Running Interactive Tools Like WBADMIN

  • wbadmin can fail if run from OOBE or very early first logon, especially if Shadow Copy services are not fully functional yet, or the target disk is not writable.

Alternatives:

  • Test running the script manually after setup completes (as admin) to see if it runs without issues.
  • Delay backup until setup is 100% complete, e.g., via Task Scheduler with a delay.

Network or Removable Storage?

  • If targeting a network share, map it first:
    Code:
    net use Z: \\server\backupshare /user:username password
    wbadmin start backup -backupTarget:Z: -allCritical -quiet

5. SetupComplete.cmd Specifics

  • Do not require user interaction. If any scripted command stops and waits for a prompt, the entire setup hangs.
  • No GUI/output is shown.

6. Testing and Isolation

  • Try running each line individually in a command prompt after the OS is set up.
  • Check paths for winre.wim and make sure your backup target (D: or network share) exists and is writeable.

Recommendations:​

  • Post your log file or error message here for precise troubleshooting.
  • If you’re working from a specific deployment, let me know which Windows version and what your drive layout looks like.
In summary:
Add logging, isolate which command fails, check the state of all needed files/folders/targets, and confirm all paths. Post any error output for help on that exact step!

should i put this with the other script
 

Yes, you should combine the logging version of the script with your existing recovery and backup commands, especially for troubleshooting during Windows unattended setup. This approach gives you a clear, step-by-step log (C:\setup_log.txt) so you know exactly which command fails.

Here’s How You Can Combine Everything​

Place the following in your SetupComplete.cmd or as a batch file called by your unattend XML:
Code:
[USER=35331]@echo[/USER] off
set LOGFILE=C:\setup_log.txt
echo %DATE% %TIME% - Starting Recovery and Backup > %LOGFILE%

echo Creating recovery folder... >> %LOGFILE%
md C:\Recovery\WindowsRE >> %LOGFILE% 2>&1

echo Copying winre.wim... >> %LOGFILE%
copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim >> %LOGFILE% 2>&1

echo Registering WinRE image... >> %LOGFILE%
reagentc /setreimage /path C:\Recovery\WindowsRE >> %LOGFILE% 2>&1

echo Enabling WinRE... >> %LOGFILE%
reagentc /enable >> %LOGFILE% 2>&1

echo Starting wbadmin backup... >> %LOGFILE%
wbadmin start backup -backupTarget:D: -allCritical -quiet >> %LOGFILE% 2>&1

echo %DATE% %TIME% - Script Complete >> %LOGFILE%

Why This Is Smart​

  • Single script = simpler troubleshooting and fewer moving parts.
  • **Log file*** shows you if—for example—copy, reagentc, or wbadmin is failing. You’ll know what to fix.
  • You can tweak, comment out, or re-order steps for your needs.

How to use:
  • Place in C:\Windows\Setup\Scripts\SetupComplete.cmd
  • Or schedule/run the script via the FirstLogonCommands or a scheduled task after first boot.

If You Hit An Error:​

  • Boot into Windows, open C:\setup_log.txt, and read the last lines—the error will be clear.
  • Post that error here if you need tailored help!

In summary: Yes, run the logging version as your “master” script for both WinRE setup and backup. This makes deployment troubleshooting vastly easier.
 

Yes, you should combine the logging version of the script with your existing recovery and backup commands, especially for troubleshooting during Windows unattended setup. This approach gives you a clear, step-by-step log (C:\setup_log.txt) so you know exactly which command fails.

Here’s How You Can Combine Everything​

Place the following in your SetupComplete.cmd or as a batch file called by your unattend XML:
Code:
[USER=35331]@echo[/USER] off
set LOGFILE=C:\setup_log.txt
echo %DATE% %TIME% - Starting Recovery and Backup > %LOGFILE%

echo Creating recovery folder... >> %LOGFILE%
md C:\Recovery\WindowsRE >> %LOGFILE% 2>&1

echo Copying winre.wim... >> %LOGFILE%
copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim >> %LOGFILE% 2>&1

echo Registering WinRE image... >> %LOGFILE%
reagentc /setreimage /path C:\Recovery\WindowsRE >> %LOGFILE% 2>&1

echo Enabling WinRE... >> %LOGFILE%
reagentc /enable >> %LOGFILE% 2>&1

echo Starting wbadmin backup... >> %LOGFILE%
wbadmin start backup -backupTarget:D: -allCritical -quiet >> %LOGFILE% 2>&1

echo %DATE% %TIME% - Script Complete >> %LOGFILE%

Why This Is Smart​

  • Single script = simpler troubleshooting and fewer moving parts.
  • **Log file*** shows you if—for example—copy, reagentc, or wbadmin is failing. You’ll know what to fix.
  • You can tweak, comment out, or re-order steps for your needs.

How to use:
  • Place in C:\Windows\Setup\Scripts\SetupComplete.cmd
  • Or schedule/run the script via the FirstLogonCommands or a scheduled task after first boot.

If You Hit An Error:​

  • Boot into Windows, open C:\setup_log.txt, and read the last lines—the error will be clear.
  • Post that error here if you need tailored help!

In summary: Yes, run the logging version as your “master” script for both WinRE setup and backup. This makes deployment troubleshooting vastly easier.

it doesn't work do you sometimes have a screenshot of
 

I'm unable to provide a direct screenshot since I can't run Windows setup or scripts myself; however, I can help you analyze what should happen and what your log/output should look like.
What to expect when using the script:
  • After setup and first login, you should find C:\setup_log.txt.
  • Its lines would look similar to this:
    Code:
    07/01/2024 13:41:12 - Starting Recovery and Backup
    Creating recovery folder...
    Copying winre.wim...
    Registering WinRE image...
    Enabling WinRE...
    Starting wbadmin backup...
    07/01/2024 13:41:28 - Script Complete
  • If an error occurs at any step, you’d see an error message after the relevant line (such as “The system cannot find the file specified,” or “Access is denied”).
If it DOESN’T work:
  • C:\setup_log.txt will be missing or incomplete.
  • The step that fails will have an error message after its line.
  • If no log is present, the script wasn’t run or failed to execute at all—typically due to a path error or a problem with the script’s entry in SetupComplete.cmd or your unattend file.
What you should do now:
  1. Check for C:\setup_log.txt. If found, open it and paste the contents here for analysis.
  2. If the log isn’t there:
    • Check that your SetupComplete.cmd is definitely located at C:\Windows\Setup\Scripts\SetupComplete.cmd.
    • Make sure there are no syntax errors or encoding issues (it must use Windows line endings and plain ASCII/UTF-8 text, not rich text or Word formatting).
    • Ensure the script has execute permissions and isn’t blocked (“Unblock” it if you copied from another PC).
If you’ve uploaded a log or related file, let me know and I can locate/analyze it for you for next troubleshooting steps.
If you want visuals:
You can search for screenshots of C:\setup_log.txt output with error messages on Microsoft forums or tech blogs. It will look much like standard Windows command prompt batch script text logs.
If you attach or copy the actual log/output (or the error you see), I can give you step-by-step targeted help!
 

I'm unable to provide a direct screenshot since I can't run Windows setup or scripts myself; however, I can help you analyze what should happen and what your log/output should look like.
What to expect when using the script:
  • After setup and first login, you should find C:\setup_log.txt.
  • Its lines would look similar to this:
    Code:
    07/01/2024 13:41:12 - Starting Recovery and Backup
    Creating recovery folder...
    Copying winre.wim...
    Registering WinRE image...
    Enabling WinRE...
    Starting wbadmin backup...
    07/01/2024 13:41:28 - Script Complete
  • If an error occurs at any step, you’d see an error message after the relevant line (such as “The system cannot find the file specified,” or “Access is denied”).
If it DOESN’T work:
  • C:\setup_log.txt will be missing or incomplete.
  • The step that fails will have an error message after its line.
  • If no log is present, the script wasn’t run or failed to execute at all—typically due to a path error or a problem with the script’s entry in SetupComplete.cmd or your unattend file.
What you should do now:
  1. Check for C:\setup_log.txt. If found, open it and paste the contents here for analysis.
  2. If the log isn’t there:
    • Check that your SetupComplete.cmd is definitely located at C:\Windows\Setup\Scripts\SetupComplete.cmd.
    • Make sure there are no syntax errors or encoding issues (it must use Windows line endings and plain ASCII/UTF-8 text, not rich text or Word formatting).
    • Ensure the script has execute permissions and isn’t blocked (“Unblock” it if you copied from another PC).
If you’ve uploaded a log or related file, let me know and I can locate/analyze it for you for next troubleshooting steps.
If you want visuals:
You can search for screenshots of C:\setup_log.txt output with error messages on Microsoft forums or tech blogs. It will look much like standard Windows command prompt batch script text logs.
If you attach or copy the actual log/output (or the error you see), I can give you step-by-step targeted help!


what is the full script for recovery and backup for where i should put it for windows 11 home
 

Attachments

  • Screenshot 2025-05-28 at 17.26.12.webp
    Screenshot 2025-05-28 at 17.26.12.webp
    35.1 KB · Views: 0
Here is the most complete script for recovery environment registration and user-data backup that will work on Windows 11 Home. Please note that Windows 11 Home does not support full system image backup via wbadmin, so this script will only handle enabling WinRE (Windows Recovery Environment) and making a backup copy of user profiles (not the entire system image).

Example Batch Script: Recovery and User Data Backup​

Code:
[USER=35331]@echo[/USER] off
set LOGFILE=C:\setup_log.txt
echo %DATE% %TIME% - Starting Recovery and Data Backup > %LOGFILE%

:: Create recovery folder
echo Creating recovery folder... >> %LOGFILE%
md C:\Recovery\WindowsRE >> %LOGFILE% 2>&1

:: Copy winre.wim if available
echo Copying winre.wim... >> %LOGFILE%
if exist C:\Windows\System32\Recovery\Winre.wim (
    copy C:\Windows\System32\Recovery\Winre.wim C:\Recovery\WindowsRE\Winre.wim >> %LOGFILE% 2>&1
) else (
    echo winre.wim not found, skipping copy >> %LOGFILE%
)

:: Register and enable WinRE
echo Registering WinRE image... >> %LOGFILE%
reagentc /setreimage /path C:\Recovery\WindowsRE >> %LOGFILE% 2>&1

echo Enabling WinRE... >> %LOGFILE%
reagentc /enable >> %LOGFILE% 2>&1

:: Backup user profiles to D: (change D: to your backup drive)
echo Backing up user profiles... >> %LOGFILE%
if exist D:\ (
    xcopy /E /I /H /C /Y C:\Users D:\UserBackup >> %LOGFILE% 2>&1
    echo Profiles backed up to D:\UserBackup >> %LOGFILE%
) else (
    echo Backup drive D: not found, skipping backup >> %LOGFILE%
)

echo %DATE% %TIME% - Script Complete >> %LOGFILE%

How to Use​

  1. Save the script as:
    C:\Windows\Setup\Scripts\SetupComplete.cmd
    • Create the folder if it does not exist.
  2. Backup destination:
    • The above script copies user profiles to D:\UserBackup. Change D: to any external or second internal drive with enough space.
    • If you don’t have a D: drive, update to another drive letter, network share, or USB drive.
  3. Review the log:
    • After setup, check C:\setup_log.txt for errors and results.

Notes​

  • This is not a true system image backup. For that, you would need to use a third-party backup tool (such as Macrium Reflect, AOMEI, or similar) which you can also call at the end of this script if you silently install those tools.
  • reagentc commands are included to ensure the recovery environment is registered and enabled.
  • xcopy is used for user profile data backup, which is the closest built-in equivalent to a full backup for Home editions.

If You Need Full System Image Backup on Home Edition​

  • You must download/install and silently invoke a tool like:
    • Macrium Reflect Free or Paid:
      Example silent backup command:
      "C:\Program Files\Macrium\Reflect\Reflect.exe" -e -w -full -img D:\Backup\WinHomeBackup.mrimg --auto
    • AOMEI Backupper Standard (free for personal use).
    • Acronis, EaseUS, etc. (many have silent command-line options).
Let me know if you want a ready-to-use scripted example for Macrium, AOMEI, or EaseUS!

Summary:
  • Place this script as SetupComplete.cmd for automatic post-setup execution.
  • It registers WinRE and copies user profiles for backup on Windows 11 Home.
  • For true full-system backup, use a third-party backup tool in similar fashion.
Let me know if you want the script to install and trigger third-party image backup utilities automatically!
 

Back
Top