How to restore backup tokens.dat in OOBE or SetupComplete

Discussion in 'Scripting' started by Chibi ANUBIS, May 21, 2015.

  1. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    729
    404
    30
    Hello all it's me again ! :p
    I use Microsoft Toolkit for activation backup, but I wonder if there is a method to restore the activation during installation.
    Thanks for all :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. NICK@NUMBER11

    NICK@NUMBER11 MDL Expert

    Mar 23, 2010
    1,354
    633
    60
    #2 NICK@NUMBER11, May 21, 2015
    Last edited by a moderator: Apr 20, 2017
    yes,

    create a folder $oem$\$1\Windows\AutoKMS - copy to this AutoKMS.exe

    copy this and save as setupcomplete.cmd and save in $oem$\$$\Setup\scripts

    Code:
    @echo off
    pushd %~dp0
    
    ::::::::::BEGIN ACTIVATION STUFF::::::::::::::::::::::
    :Install Exclusion in Windows Defender for future blocks. Has to be done during Windows Setup or you won't have permissions.
    REG ADD "HKLM\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths" /v "%WinDir%\AutoKMS\AutoKMS.exe" /D 0 /T REG_DWORD /F
    
    :Activate Windows
    %WinDir%\AutoKMS\AutoKMS.exe
    set status=
    
    for /l %%x in (1, 1, 3) do (
    for /f "tokens=2 delims== " %%A in ('"wmic path SoftwareLicensingProduct where (Name LIKE '%%Windows%%') get LicenseStatus /format:list"') do (
          if %%A geq 1 set status=%%A
    )
    
    if %status% EQU 1 Goto :END-ACTIVATION-STUFF
    %WinDir%\AutoKMS\AutoKMS.exe
    )
    :END-ACTIVATION-STUFF
    
    RMDIR /S /Q "C:\Windows\Setup\Scripts"
    exit
     
  3. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    729
    404
    30
    Thanks ! :D
    Where I find the "AutoKMS.exe" ?
    And I put the backup folder and AutoKMS in the same folder ?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. NICK@NUMBER11

    NICK@NUMBER11 MDL Expert

    Mar 23, 2010
    1,354
    633
    60
    you said that you used ms toolkit to activate, so you will find the AutoKMS.exe in this location "C:\Windows\AutoKMS".

    if you are wanting to backup and reinstall the tokens.dat & data.dat, then you will need to inject them into the install.wim
     
  5. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    729
    404
    30
    Ok thanks for all ;)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    729
    404
    30
    I thought there was a way to do it with setupcomplete.cmd to restore the tokens.dat :(
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. NICK@NUMBER11

    NICK@NUMBER11 MDL Expert

    Mar 23, 2010
    1,354
    633
    60
    #7 NICK@NUMBER11, May 21, 2015
    Last edited by a moderator: Apr 20, 2017
    may i am not sure the other method i have used is this ....


    create a folder

    c:\wmc

    then within that folder create a new folder activation

    c:\wmc\activation\

    copy the 2 files that you backup up tokens.dat & data.dat to the activation folder

    then copy the install.wim to the wmc folder from the windows 8 iso its found in the sources folder

    copy the following and save it in the wmc folder call it inject.cmd

    Code:
    MD %~dp0MOUNT
    DISM /Mount-Wim /WimFile:c:\WMC\install.wim /index:1 /MountDir:c:\WMC\mount
    attrib -H  c:\WMC\mount\Windows\System32\spp\store\2.0\data.dat /S
    del /s /f /q c:\WMC\mount\Windows\System32\spp\store\2.0\Data.dat
    del /s /f /q c:\WMC\mount\Windows\System32\spp\store\2.0\Tokens.dat
    attrib -H c:\wmc\Activation\data.dat /S
    COPY /y c:\wmc\Activation\data.dat c:\WMC\mount\Windows\System32\spp\store\2.0\data.dat
    COPY /Y c:\wmc\Activation\tokens.dat c:\WMC\mount\Windows\System32\spp\store\2.0\tokens.dat
    attrib +H c:\WMC\mount\Windows\System32\spp\store\2.0\data.dat /S
    attrib +H c:\wmc\Activation\data.dat /S
    Dism.exe /Unmount-Wim /MountDir:%~dp0MOUNT /commit

    once complete copy the updated install.wim back to the iso and yo have your very own install activation complete for your pc!
     
  8. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    729
    404
    30
    #8 Chibi ANUBIS, May 21, 2015
    Last edited by a moderator: Apr 20, 2017
    (OP)
    We can probably use in SetupComplete.cmd or OOBE.cmd this :

    Code:
    attrib -H "%windir%\System32\spp\store\2.0\data.dat" /S 
    del /s /f /q "%windir%\System32\spp\store\2.0\Data.dat" 
    del /s /f /q "%windir%\System32\spp\store\2.0\Tokens.dat" 
    COPY /y "%~dp0data.dat" "%windir%\System32\spp\store\2.0\data.dat" 
    COPY /Y "%~dp0tokens.dat" "%windir%\System32\spp\store\2.0\tokens.dat" 
    attrib +H "%windir%\System32\spp\store\2.0\data.dat" /S 
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. NICK@NUMBER11

    NICK@NUMBER11 MDL Expert

    Mar 23, 2010
    1,354
    633
    60
  10. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    729
    404
    30
    Don't work for the Windows 8.1 Update 1 :(
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. NICK@NUMBER11

    NICK@NUMBER11 MDL Expert

    Mar 23, 2010
    1,354
    633
    60
    Oh yeh so i read also, try the setupcomplete by just adding

    attrib -H "%windir%\System32\spp\store\2.0\data.dat" /S
    del /s /f /q "%windir%\System32\spp\store\2.0\Data.dat"
    del /s /f /q "%windir%\System32\spp\store\2.0\Tokens.dat"
    COPY /y "%~dp0data.dat" "%windir%\System32\spp\store\2.0\data.dat"
    COPY /Y "%~dp0tokens.dat" "%windir%\System32\spp\store\2.0\tokens.dat"
    attrib +H "%windir%\System32\spp\store\2.0\data.dat" /S