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

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

  1. polinom

    polinom MDL Novice

    Jun 21, 2011
    11
    0
    0
    Thanks a lot ..very useful info!
     
  2. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #202 timesurfer, Sep 29, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    MD's VL activator

    Use with
    Code:
    Keygen.exe
    Code:
    @echo off
    mode con cols=70 lines=7
    title KMS Activation Script for Z.W.T Keygen
    start /B /D "%~dp0" Keygen.exe>NUL 2>&1
    call :windows
    call :office
    taskkill /IM "Keygen.exe" /f>NUL 2>&1
    exit
     
    :windows
    cls
    setlocal enabledelayedexpansion
    set spp=SoftwareLicensingProduct
    set sps=SoftwareLicensingService
    for /f "tokens=2 delims==" %%A IN ('"wmic path %sps% get version /format:list"') do set ver=%%A
    if defined ver ( for /f "tokens=2 delims==" %%A in ('"wmic path %spp% where (Description LIKE '%%KMSCLIENT%%') get ID /format:list"') do set wid=%%A
    if defined wid ( set /a win=0
    for /f "tokens=2 delims==" %%A in ('"wmic path %sps% where version='%ver%' get KeyManagementServiceMachine /format:list"') do if not %%A==localhost wmic path %sps% where version='%ver%' call SetKeyManagementServiceMachine MachineName="localhost">NUL 2>&1
    for /f "tokens=2 delims==" %%A in ('"wmic path %spp% where (Description LIKE '%%KMSCLIENT%%') get LicenseStatus /format:list"') do set /a wpk=%%A
    if not !wpk! EQU 1 ( call :insKey !wid!
    wmic path %sps% where version='%ver%' call RefreshLicenseStatus>NUL 2>&1
    )
    call :activate !wid!
    )
    )
    If not defined win ( set msg=No supported Windows OS detected...
    cls
    echo !msg!
    call :speak "!msg!"
    )
    endlocal
    exit /b
     
    :office
    cls
    setlocal enabledelayedexpansion
    set spp=OfficeSoftwareProtectionProduct
    set sps=OfficeSoftwareProtectionService
    for /f "tokens=2 delims==" %%A IN ('"wmic path %sps% get version /format:list"') do set ver=%%A
    if defined ver ( for /f "tokens=2 delims==" %%A in ('"wmic path %sps% where version='%ver%' get KeyManagementServiceMachine /format:list"') do if not %%A==localhost wmic path %sps% where version='%ver%' call SetKeyManagementServiceMachine MachineName="localhost">NUL 2>&1
    set vis="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office14.VISIO"
    reg query !vis!>NUL 2>&1
    if !ERRORLEVEL! EQU 1 ( set vis="HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Office14.VISIO"
    reg query !vis!>NUL 2>&1
    )
    IF !ERRORLEVEL! EQU 0 for /f "tokens=3" %%A in ('"reg query !vis!| findstr /i "SPPSkuid""') do call :visio %%A
    for /f "tokens=2 delims==" %%A in ('"wmic path %spp% where (Description LIKE '%%KMSCLIENT%%') get ID /format:list"') do call :chkey %%A
    ) else ( set msg=No supported Office product detected...
    cls
    echo !msg!
    call :speak "!msg!"
    )
    endlocal
    exit /b
     
    :chkey
    setlocal enabledelayedexpansion
    wmic path %spp% where ID='%1' get Name|Findstr "Visio">NUL
    if %ERRORLEVEL% EQU 1 ( for /f "tokens=2 delims==" %%A in ('"wmic path %spp% where ID='%1' get LicenseStatus /format:list"') do ( set /a ls=%%A
    if not !ls! EQU 1 call :insKey %1
    call :activate %1
    )
    )
    endlocal
    exit /b
     
    :visio
    setlocal enabledelayedexpansion
    set file="%~dp0key.vbs"
    echo WScript.Echo (LCase("%1"))>%file%
    for /f %%A in ('cscript /nologo %file%') do set id=%%A
    del "%~dp0key.vbs"
    call set id=%id:\0=%
    for /f "tokens=2 delims==" %%A in ('"wmic path %spp% where ID='%id%' get LicenseStatus /format:list"') do ( set /a ls=%%A
    if not !ls! EQU 1 call :insKey %id%
    call :activate %id%
    )
    endlocal
    exit /b
     
    :activate
    cls
    echo.
    for /f "tokens=2 delims==" %%x in ('"wmic path %spp% where ID='%1' get Name /format:list"') do echo Attempting to activate %%x
    set /p var=No. of Activation Attempts:  <NUL
    set /a retry=0
    :act
    wmic path %spp% where ID='%1' call Activate>NUL 2>&1
    set /a retry=%retry%+1
    set /p var=%retry%<NUL
    for /f "tokens=2 delims==" %%x in ('"wmic path %spp% where ID='%1' get GracePeriodRemaining /format:list"') do set gpr=%%x
    if %gpr% LSS 259200 if %retry% LSS 10 goto act
    set /a gpr=%gpr%/60/24
    echo.
    echo Remaining Period: %gpr% day(s)
    echo.
    if %gpr% EQU 180 ( set msg=Product Activation Successful
    echo !msg!
    call :speak "!msg!"
    ) else ( set msg=Product Activation Failed
    echo !msg!
    call :speak "!msg!"
    )
    exit /b
    
    :speak
    echo CreateObject("SAPI.SpVoice").Speak %1 >"%~dp0vc.vbs"
    "%~dp0vc.vbs" & del "%~dp0vc.vbs"
    exit /b
    
    
    :insKey
    cls
    echo.
    for /f "tokens=2 delims==" %%A in ('"wmic path %spp% where ID='%1' get Name /format:list"') do echo Installing Key for %%A
    set file="%~dp0key.vbs"
    echo edition = "%1">%file%
    echo Set keys = CreateObject ("Scripting.Dictionary")>>%file%
    echo keys.Add "6f327760-8c5c-417c-9b61-836a98287e0c", "VYBBJ-TRJPB-QFQRF-QFT4D-H3GVB">>%file%
    echo keys.Add "9da2a678-fb6b-4e67-ab84-60dd6a9c819a", "V7QKV-4XVVR-XYV4D-F7DFM-8R6BM">>%file%
    echo keys.Add "ea509e87-07a1-4a45-9edc-eba5a39f36af", "D6QFG-VBYP2-XQHM7-J97RH-VVRCK">>%file%
    echo keys.Add "8ce7e872-188c-4b98-9d90-f8f90b7aad02", "V7Y44-9T38C-R2VJK-666HK-T7DDX">>%file%
    echo keys.Add "cee5d470-6e3b-4fcc-8c2b-d17428568a9f", "H62QG-HXVKF-PP4HP-66KMR-CW9BM">>%file%
    echo keys.Add "8947d0b8-c33b-43e1-8c56-9b674c052832", "QYYW6-QP4CB-MBV6G-HYMCJ-4T3J4">>%file%
    echo keys.Add "ca6b6639-4ad6-40ae-a575-14dee07f6430", "K96W8-67RPQ-62T9Y-J8FQJ-BT37T">>%file%
    echo keys.Add "ab586f5c-5256-4632-962f-fefd8b49e6f4", "Q4Y4M-RHWJM-PY37F-MTKWH-D3XHX">>%file%
    echo keys.Add "ecb7c192-73ab-4ded-acf4-2399b095d0cc", "7YDC2-CWM8M-RRTJC-8MDVC-X3DWQ">>%file%
    echo keys.Add "45593b1d-dfb1-4e91-bbfb-2d5d0ce2227a", "RC8FX-88JRY-3PF7C-X8P67-P4VTT">>%file%
    echo keys.Add "df133ff7-bf14-4f95-afe3-7b48e7e331ef", "YGX6F-PGV49-PGW3J-9BTGG-VHKC6">>%file%
    echo keys.Add "5dc7bf61-5ec9-4996-9ccb-df806a2d0efe", "4HP3K-88W3F-W2K3D-6677X-F9PGB">>%file%
    echo keys.Add "b50c4f75-599b-43e8-8dcd-1081a7967241", "BFK7F-9MYHM-V68C7-DRQ66-83YTP">>%file%
    echo keys.Add "2d0882e7-a4e7-423b-8ccc-70d91e0158b1", "HVHB3-C6FV7-KQX9W-YQG79-CRY7T">>%file%
    echo keys.Add "92236105-bb67-494f-94c7-7f7a607929bd", "D9DWC-HPYVV-JGF4P-BTWQB-WX8BJ">>%file%
    echo keys.Add "e558389c-83c3-4b29-adfe-5e4d7f46c358", "7MCW8-VRQVK-G677T-PDJCM-Q8TCP">>%file%
    echo keys.Add "9ed833ff-4f92-4f36-b370-8683a4f13275", "767HD-QGMWX-8QTDB-9G3R2-KHFGJ">>%file%
    echo keys.Add "09ed9640-f020-400a-acd8-d7d867dfd9c2", "YBJTT-JG6MD-V9Q7P-DBKXJ-38W9R">>%file%
    echo keys.Add "ef3d4e49-a53d-4d81-a2b1-2ca6c2556b2c", "7TC2V-WXF6P-TD7RT-BQRXR-B8K32">>%file%
    echo keys.Add "ae2ee509-1b34-41c0-acb7-6d4650168915", "33PXH-7Y6KF-2VJC9-XBBR8-HVTHH">>%file%
    echo keys.Add "46bbed08-9c7b-48fc-a614-95250573f4ea", "C29WB-22CC8-VJ326-GHFJW-H9DH4">>%file%
    echo keys.Add "1cb6d605-11b3-4e14-bb30-da91c8e3983a", "YDRBP-3D83W-TY26F-D46B2-XCKRJ">>%file%
    echo keys.Add "b92e9980-b9d5-4821-9c94-140f632f6312", "FJ82H-XT6CR-J8D7P-XQJJ2-GPDD4">>%file%
    echo keys.Add "5a041529-fef8-4d07-b06f-b59b573b32d2", "W82YF-2Q76Y-63HXB-FGJG9-GF7QX">>%file%
    echo keys.Add "54a09a0d-d57b-4c10-8b69-a842d6590ad5", "MRPKT-YTG23-K7D7T-X2JMM-QY7MG">>%file%
    echo keys.Add "7482e61b-c589-4b7f-8ecc-46d455ac3b87", "74YFP-3QFB3-KQT8W-PMXWJ-7M648">>%file%
    echo keys.Add "620e2b3d-09e7-42fd-802a-17a13652fe7a", "489J6-VHDMP-X63PK-3K798-CPX3Y">>%file%
    echo keys.Add "8a26851c-1c7e-48d3-a687-fbca9b9ac16b", "GT63C-RJFQ3-4GMB6-BRFB9-CB83V">>%file%
    echo keys.Add "f772515c-0e87-48d5-a676-e6962c3e1195", "736RG-XDKJK-V34PF-BHK87-J6X3K">>%file%
    echo keys.Add "cda18cf3-c196-46ad-b289-60c072869994", "TT8MH-CG224-D3D7Q-498W2-9QCTX">>%file%
    echo keys.Add "68531fb9-5511-4989-97be-d11a0f55633f", "YC6KT-GKW9T-YTKYR-T4X34-R7VHC">>%file%
    echo keys.Add "a78b8bd9-8017-4df5-b86a-09f756affa7c", "6TPJF-RBVHG-WBW2R-86QPH-6RTM4">>%file%
    echo keys.Add "4f3d1606-3fea-4c01-be3c-8d671c401e3b", "YFKBB-PQJJV-G996G-VWGXY-2V3X8">>%file%
    echo keys.Add "2c682dc2-8b68-4f63-a165-ae291d4cf138", "HMBQG-8H2RH-C77VX-27R82-VMQBT">>%file%
    echo keys.Add "cfd8ff08-c0d7-452b-9f60-ef5c70c32094", "VKK3X-68KWM-X2YGT-QR4M6-4BWMV">>%file%
    echo keys.Add "d4f54950-26f2-4fb4-ba21-ffab16afcade", "VTC42-BM838-43QHV-84HX6-XJXKV">>%file%
    echo keys.Add "7afb1156-2c1d-40fc-b260-aab7442b62fe", "RCTX3-KWVHP-BR6TB-RB6DM-6X7HP">>%file%
    echo keys.Add "68b6e220-cf09-466b-92d3-45cd964b9509", "7M67G-PC374-GR742-YH8V4-TCBY3">>%file%
    echo keys.Add "fd09ef77-5647-4eff-809c-af2b64659a45", "22XQ2-VRXRG-P8D42-K34TD-G3QQC">>%file%
    echo keys.Add "c1af4d90-d1bc-44ca-85d4-003ba33db3b9", "YQGMW-MPWTJ-34KDK-48M3W-X4Q6V">>%file%
    echo keys.Add "8198490a-add0-47b2-b3ba-316b12d647b4", "39BXF-X8Q23-P2WWT-38T2F-G3FPG">>%file%
    echo keys.Add "01ef176b-3e0d-422a-b4f8-4ea880035e8f", "4DWFP-JF3DJ-B7DTH-78FJB-PDRHK">>%file%
    echo keys.Add "ad2542d4-9154-4c6d-8a44-30f11ee96989", "TM24T-X9RMF-VWXK6-X8JC9-BFGM2">>%file%
    echo keys.Add "2401e3d0-c50a-4b58-87b2-7e794b7d2607", "W7VD6-7JFBR-RX26B-YKQ3Y-6FFFJ">>%file%
    echo keys.Add "ddfa9f7c-f09e-40b9-8c1a-be877a9a7f4b", "WYR28-R7TFJ-3X2YQ-YCY4H-M249D">>%file%
    echo if keys.Exists(edition) then>>%file%
    echo WScript.Echo keys.Item(edition)>>%file%
    echo End If>>%file%
    for /f %%A in ('cscript /nologo %file%') do set key=%%A
    del %file%
    wmic path %sps% where version='%ver%' call InstallProductKey ProductKey="%key%">NUL 2>&1
    exit /b
     
  3. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,513
    7,174
    120
    Yeah, good work :worthy:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. calpo

    calpo MDL Member

    Apr 23, 2010
    212
    60
    10
    @Josh Cell & timesufer

    I just wonder if you two have a KMS Server script ( .bat or .cmd files ) to activate Office 2010 VL ?

    Thanks a lot in advance.
     
  5. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,513
    7,174
    120
    Online Server?

    Well, exists this servers, more, the security form is provide an Keygen, for generate the license ID by PID in the script ...

    @timesurfer

    You can write all bytes on the Keygen.exe on HDD using the batch compilation, generating one .CMD for KMS Activation, instead of .cmd + .exe :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #206 timesurfer, Oct 22, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    How to delete the files with extension .torrent files with task daily?

    Here is the path:

    Code:
    C:\Users\Username\AppData\Roaming\uTorrent
    This is so no .torrent files are ever on your system

    Good luck :eek:
     
  7. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,513
    7,174
    120
    #207 Josh Cell, Oct 22, 2011
    Last edited by a moderator: Apr 20, 2017
    Code:
    DEL /F /S /Q "C:\Users\Username\AppData\Roaming\uTorrent\*.torrent"
    :eek::eek::eek:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #208 timesurfer, Oct 23, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Almost :p...lol

    Install a task that deletes all ".torrent" files in that location every 7 hrs silently
     
  9. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,513
    7,174
    120
    This is code delete all .torrent files stored in the folder every invoke :eek::eek::eek:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    So you have to create task to run it auto :p

    So one create task, two create your file in C:\ and three run silently with one batch file to do everything :yoda:
     
  11. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #211 timesurfer, Oct 23, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Almost done :eek:

    TorrentRemovalTask - (TRT)

    Code:
    @echo off
    schtasks /create /tn "TRT" /tr "%SystemDrive%\TRT\TRT.bat" /sc %daily% /mo 1 /ru "" >NUL
    SET file=%SystemDrive%\TRT\TRT.bat
    IF EXIST %file% attrib -h %file% 
    echo @echo off >%file%
    echo DEL /F /S /Q "C:\Users\Username\AppData\Roaming\uTorrent\*.torrent" >>%file%
     
  12. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,513
    7,174
    120
    #212 Josh Cell, Oct 23, 2011
    Last edited by a moderator: Apr 20, 2017
    :eek::eek::eek:

    You can replace the Username by an variable:

    Code:
    %USERNAME%
    or:

    Code:
    %APPDATA%
    For direct see the AppData folder

    Automated Tool :sith:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #213 timesurfer, Oct 23, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Code:
    @echo off
    schtasks /create /tn "TRT" /tr "%SystemDrive%\TRT\TRT.bat" /sc %daily% /mo 1 /ru "" >NUL
    SET file=%SystemDrive%\TRT\TRT.bat
    IF EXIST %file% attrib -h %file% 
    echo @echo off >%file%
    echo DEL /F /S /Q "C:\Users\%USERNAME%\AppData\Roaming\uTorrent\*.torrent" >>%file%
    Thanks so one bat is needed to put your code in bat file in C:\ and also creates task to run that file daily :p

    Right now my .bat doesn't work for either task or C:\ file with your code to delete .torrent files :yoda:
     
  14. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,513
    7,174
    120
    The %DAILY% variable not exists on the code :eek::eek::eek:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    You are going way to fast for reality :p

    Re-read my post's and complete the project challenge :yoda:

    You have 420 minutes 42 seconds 0 mil seconds

    Your prize awaits you
     
  16. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,513
    7,174
    120
    I've some ideas for this code in C# :eek::eek::eek:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. calpo

    calpo MDL Member

    Apr 23, 2010
    212
    60
    10
    @ Josh Cell

    Can you help me how to create a file .cmd or .bat that it will make a folder named Back-up on Desktop automatically and copy the file tokens.dat and cache.dat into Back-up folder , the path below-mentioned.

    tokens.dat ( in OfficeSoftwareProtectionPlatform folder )

    C:\ProgramData\Microsoft\OfficeSoftwareProtectionPlatform

    cache.dat ( in Cache folder )
    C:\ProgramData\Microsoft\OfficeSoftwareProtectionPlatform\Cache


    Thanks a lot for your help in advance.
     
  18. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,513
    7,174
    120
    Replied your PM ...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,513
    7,174
    120
    #219 Josh Cell, Nov 8, 2011
    Last edited by a moderator: Apr 20, 2017
    Backup Code

    Code:
    @ECHO OFF
    echo Killing the OSPPSVC SERVICE PROCCESS
    net stop osppsvc>NUL
    taskkill /IM "osppsvc">NUL
    echo Copying Tokens.dat File to Desktop
    COPY /Y "%PROGRAMDATA%\Microsoft\OfficeSoftwareProtectionPlatform\tokens.dat" "%USERPROFILE%\Desktop\tokens.dat"
    echo Copying Cache.dat File to Desktop
    COPY /Y "%PROGRAMDATA%\Microsoft\OfficeSoftwareProtectionPlatform\Cache\cache.dat" "%USERPROFILE%\Desktop\cache.dat"
    net start osppsvc >NUL
    Restore Code

    Code:
    @ECHO OFF
    echo Killing the OSPPSVC SERVICE PROCCESS
    net stop osppsvc>NUL
    taskkill /IM "osppsvc">NUL
    echo Restoring Tokens.dat File
    COPY /Y  "%USERPROFILE%\Desktop\tokens.dat" "%PROGRAMDATA%\Microsoft\OfficeSoftwareProtectionPlatform\tokens.dat">NUL
    echo Restoring Cache.dat File
    COPY /Y  "%USERPROFILE%\Desktop\cache.dat" "%PROGRAMDATA%\Microsoft\OfficeSoftwareProtectionPlatform\Cache\cache.dat">NUL
    net start osppsvc >NUL
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. calpo

    calpo MDL Member

    Apr 23, 2010
    212
    60
    10
    @ Josh Cell

    Thankyou for your help. It works .... It copies 2 files on Desktop. Please do me one more favor.

    Can you add a command line that automatically create a folder named Backup on desktop containing these two files in that folder ?

    Thanks again.

    Have a good day !