[Batch] The Official Batch File Repository - Learn & ask questions about batch files

Discussion in 'Scripting' started by timesurfer, Oct 11, 2010.

  1. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    @s1ave77 I will try it then tell you later.
     
  2. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    @s1ave77 Thanks for your help. I gave it a test .. I works well. Have a great day.
     
  3. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,377
    340
    You´re welcome...thanks for feedback :good3:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    @s1ave77 Can you help me one more Restore command that apply for windows 8 . I want to restore 2 files data.dat & tokens.dat to the path : C:\Windows\System32\spp\store and the key that I used to activate. For example the key : 12345-abcde-12345-abcde-12345. I tried to follow your command ... but it does not work .. please help me. thanks so much in advance.
     
  5. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,377
    340
    #285 s1ave77, Aug 3, 2013
    Last edited by a moderator: Apr 20, 2017
    Give me a moment :cool2:.

    Code:
    @echo off
    setlocal ENABLEDELAYEDEXPANSION
    net stop sppsvc
    takeown /F %systemroot%\System32\spp\store /A /R
    del "%systemroot%\System32\spp\store\tokens.dat" /S /Q
    del /AH "%systemroot%\System32\spp\store\data.dat" /S /Q
    xcopy "%~dp0tokens.dat" "%windir%\system32\spp\store" /S /Q /Y 
    xcopy /H "%~dp0data.dat" "%windir%\system32\spp\store" /S /Q /Y
    cscript %systemroot%\System32\slmgr.vbs /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
    net start sppsvc
    pause
    ENDLOCAL
    exit
    Needed a moment to find /H and /AH switches to copy/delete hidden system files :eek:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    #286 sanjose, Aug 3, 2013
    Last edited by a moderator: Apr 20, 2017
    Thanks s1ave77 I will give it a test and tell you if it work or not .... Have a good weekend.
     
  7. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,377
    340
    My VM says it´s working...:D.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. NICK@NUMBER11

    NICK@NUMBER11 MDL Expert

    Mar 23, 2010
    1,503
    720
    60
    #288 NICK@NUMBER11, Aug 3, 2013
    Last edited by a moderator: Apr 20, 2017
    Think this will work also...


    Code:
    @ECHO OFF
    cd %~dp0
    net stop sppsvc
    net stop sppsvc
    del /s /f /q %systemroot%\system32\spp\store\*.dat
    del /ah /s /f /q %systemroot%\system32\spp\store\*.dat
    COPY /y data.dat %windir%\System32\spp\store\data.dat
    COPY /Y tokens.dat %windir%\System32\spp\store\tokens.dat
    attrib -R -A %systemroot%\system32\spp\store\*.dat /S
    cscript %windir%\system32\slmgr.vbs /ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
    cscript %windir%\system32\slmgr.vbs /dlv
    exit
     
  9. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    #289 sanjose, Aug 13, 2013
    Last edited by a moderator: Apr 20, 2017
    @s1ave77
    I just gave a test .... It works well... if I skip the command line " cscript %systemroot%\System32\slmgr.vbs /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX "
    Thanks again Bro.
    BTW, Can you help me a .CMD file to copy 2 files " tokens.dat & data.dat " ? I do not like to copy these files manually.
    this .CMD file including:
    1. It automatically creates a folder on Desktop named Windows 8 Back-up
    2. Path for " tokens.dat & data.dat " C:\Windows\System32\spp\store
    3. It has " Press any key to open Windows 8 Back-up" as it completes copying these 2 files.
    Thanks so much in advance. Have a good day, Bro.
     
  10. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,377
    340
    Red part should be your actual Product Key, the Xs are placeholders to go conform with forum rules :D.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,377
    340
    #291 s1ave77, Aug 13, 2013
    Last edited by a moderator: Apr 20, 2017
    Code:
    @echo off
    setlocal ENABLEDELAYEDEXPANSION
    net stop sppsvc
    md "%systemdrive%\users\%username%\desktop\Windows 8 Back-up"
    xcopy /H "%windir%\system32\spp\store\data.dat" "%systemdrive%\users\%username%\desktop\Windows 8 Back-up" /S /Q /Y 
    xcopy "%windir%\system32\spp\store\tokens.dat" "%systemdrive%\users\%username%\desktop\Windows 8 Back-up" /S /Q /Y 
    net start sppsvc
    pause
    ENDLOCAL
    exit
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    I know that Xs are my Product key .... the thing is that if my product key is exceed time limit to activate online .... therefore I SKIP that line .... It works .... I try and keep that line .... it automatically activates online .... then it shows that Windows is NOT activated ! :p thanks again Bro.
     
  13. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    #293 sanjose, Aug 13, 2013
    Last edited by a moderator: Apr 20, 2017
    Thanks Bro. Can you add one more command line in order that I press Enter it will open Windows 8 Back-up folder after finish copying like " Press any key to Open Windows 8 Back-up "
     
  14. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,466
    990
    60
    #294 Humphrey, Aug 13, 2013
    Last edited by a moderator: Apr 20, 2017
    Code:
    @echo off
    setlocal ENABLEDELAYEDEXPANSION
    net stop sppsvc
    md "%systemdrive%\users\%username%\desktop\Windows 8 Back-up"
    xcopy /H "%windir%\system32\spp\store\data.dat" "%systemdrive%\users\%username%\desktop\Windows 8 Back-up" /S /Q /Y 
    xcopy "%windir%\system32\spp\store\tokens.dat" "%systemdrive%\users\%username%\desktop\Windows 8 Back-up" /S /Q /Y 
    net start sppsvc
    pause
    ENDLOCAL
    Explorer "%systemdrive%\users\%username%\desktop\Windows 8 Back-up"
    exit
    
    And why is %systemdrive%\users\%username%\desktop\ being used when it could be %userprofile%\desktop. Also, if anyone has their main account they use as a standard user and have the administrator account activated and passworded then the files will be put on the administrators account desktop (if ran as admin) and not on the current users.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,377
    340
    #295 s1ave77, Aug 13, 2013
    Last edited by a moderator: Apr 20, 2017
    Humphrey is right :D
    Code:
    @echo off
    setlocal ENABLEDELAYEDEXPANSION
    net stop sppsvc
    md "%userprofile%\desktop\Windows 8 Back-up"
    xcopy /H "%windir%\system32\spp\store\data.dat" "%userprofile%\desktop\Windows 8 Back-up" /S /Q /Y
    xcopy "%windir%\system32\spp\store\tokens.dat" "%userprofile%\desktop\Windows 8 Back-up" /S /Q /Y
    net start sppsvc
    pause
    ENDLOCAL
    Explorer "%userprofile%\desktop\Windows 8 Back-up"
    exit
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,377
    340
    #296 s1ave77, Aug 13, 2013
    Last edited by a moderator: Apr 20, 2017
    To create subfolder at actual location of the script, this avoids trouble in case several users are availeable:
    Code:
    @echo off
    setlocal ENABLEDELAYEDEXPANSION
    net stop sppsvc
    md "%~dp0Windows 8 Back-up"
    xcopy /H "%windir%\system32\spp\store\data.dat" "%~dp0Windows 8 Back-up" /S /Q /Y
    xcopy "%windir%\system32\spp\store\tokens.dat" "%~dp0Windows 8 Back-up" /S /Q /Y
    net start sppsvc
    pause
    ENDLOCAL
    Explorer "%~dp0Windows 8 Back-up"
    exit
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #297 Compo, Aug 14, 2013
    Last edited by a moderator: Apr 20, 2017
    Would it not be better to use more up to date tools than NET, XCOPY and PAUSE!
    Code:
    @ECHO OFF
    SETLOCAL
    SET "DSTD=Windows 8 Back-up"
    SC STOP sppsvc
    PUSHD %~dp0
    ROBOCOPY "%SYSTEMROOT%\SYSTEM32\SPP\STORE" "%DSTD%" data.dat tokens.dat
    SC START sppsvc
    CHOICE /C YC /M "Press Y to Open %DSTD% Folder, C to Close" /T 10 /D Y
    IF ERRORLEVEL 2 GOTO :EOF
    START "" EXPLORER "%DSTD%"
     
  18. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #298 timesurfer, Sep 18, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Anyone can figure out this problem :eek:

    I am writing this code to a batch file and it's coming out silly :eek:...lol

    Here is the write:

    Code:
    echo @echo off >%SystemDrive%\Trial\IR7\IR7.bat
    echo title IR7 >>%SystemDrive%\Trial\IR7\IR7.bat
    echo mode con: cols=51 lines=2 >>%SystemDrive%\Trial\IR7\IR7.bat
    md %SystemDrive%\Trial\IR7\IR7.bat >nul 2>&1
    echo SET file=%SystemDrive%\Trial\IR7 >>%SystemDrive%\Trial\IR7\IR7.bat
    echo IF EXIST %file% attrib -h %file% >>%SystemDrive%\Trial\IR7\IR7.bat
    echo rd /S /Q  %file% >>%SystemDrive%\Trial\IR7\IR7.bat
    Here is it written incorrectly:

    Code:
    SET file=C:\Trial
    IF EXIST \\?\Volume{5b0538e0-d236-11e2-80b1-806e6f6e6963}\\IR7.bat attrib -h \\?\Volume{5b0538e0-d236-11e2-80b1-806e6f6e6963}\\IR7.bat 
    rd /S /Q  \\?\Volume{5b0538e0-d236-11e2-80b1-806e6f6e6963}\\IR7.bat
    It should be written like this:

    Code:
    SET file=%SystemDrive%\Trial\IR7
    IF EXIST %file% attrib -h %file%
    rd /S /Q  %file%
    This work is being done in my Duality 420 thread and any help would awesome :worthy:

    It will write semi-correctly on it's own but in my full batch file it acts weird :suicide:...lol
     
  19. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #299 MasterDisaster, Sep 22, 2013
    Last edited by a moderator: Apr 20, 2017
    Try this
    Code:
    echo @echo off >%SystemDrive%\Trial\IR7\IR7.bat
    echo title IR7 >>%SystemDrive%\Trial\IR7\IR7.bat
    echo mode con: cols=51 lines=2 >>%SystemDrive%\Trial\IR7\IR7.bat
    md %SystemDrive%\Trial\IR7\IR7.bat >nul 2>&1
    echo SET file=%SystemDrive%\Trial\IR7 >>%SystemDrive%\Trial\IR7\IR7.bat
    echo IF EXIST %%file%% attrib -h %%file%% >>%SystemDrive%\Trial\IR7\IR7.bat
    echo rd /S /Q %%file%% >>%SystemDrive%\Trial\IR7\IR7.bat
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #300 timesurfer, Sep 25, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thank you for your help once more :hug2:

    It is writing correctly now :worthy:

    Come to my Rearm Wizard thread and check out the latest build...

    It will be up in a little bit with whole new first post...

    See you later...

    :shisha: