Version detection and batch creation into system drive to run version key?

Discussion in 'Scripting' started by timesurfer, Mar 17, 2014.

  1. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,068
    270
    #1 timesurfer, Mar 17, 2014
    Last edited by a moderator: Apr 20, 2017
    I have code here I want to write to %systemdrive% then detect W7 version and run

    slmgr /ipk "version key"

    Code:
    SET file=%systemdrive%\Key.bat
    echo @echo off >%file% 
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "Starter" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=7Q28W-FT9PC-CMMYT-WHMY2-89M6G >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "HomeBasic" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=YGFVB-QTFXQ-3H233-PTWTJ-YRYRV >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "HomePremium" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=RHPQ2-RMFJH-74XYM-BH4JX-XM76F >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "Professional" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=HYF8J-CVRMY-CM74G-RPHKF-PW487 >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "Ultimate" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=D4F6K-QK3RD-TMVMJ-BBMRX-3MBMV >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "StarterE" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=BRQCV-K7HGQ-CKXP6-2XP7K-F233B >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "HomeBasicE" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=VTKM9-74GQY-K3W94-47DHV-FTXJY >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "HomePremiumE" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=76BRM-9Q4K3-QDJ48-FH4F3-9WT2R >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "ProfessionalE" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=3YHKG-DVQ27-RYRBX-JMPVM-WG38T >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "UltimateE" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=TWMF7-M387V-XKW4Y-PVQQD-RK7C8 >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "StarterN" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=D4C3G-38HGY-HGQCV-QCWR8-97FFR >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "HomeBasicN" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=MD83G-H98CG-DXPYQ-Q8GCR-HM8X2 >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "HomePremiumN" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=D3PVQ-V7M4J-9Q9K3-GG4K3-F99JM >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "ProfessionalN" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=BKFRB-RTCT3-9HW44-FX3X8-M48M6 >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "UltimateN" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=HTJK6-DXX8T-TVCR6-KDG67-97J8Q >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "Enterprise" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=H7X92-3VPBB-Q799D-Y6JJ3-86WC6 >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "EnterpriseE" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=H3V6Q-JKQJG-GKVK3-FDDRF-TCKVR >>%file%
    echo REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID" | FINDSTR /I "EnterpriseN" >>%file%
    echo IF NOT ERRORLEVEL 1 SET PIDKEY=BQ4TH-BWRRY-424Y9-7PQX2-B4WBD >>%file%
    echo slmgr.vbs /ipk %PIDKEY% >>%file%
    Any better way?

    Thanks

    :shisha:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    982
    60
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,068
    270
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Compo

    Compo MDL Member

    Mar 29, 2011
    137
    104
    10
    #4 Compo, Mar 17, 2014
    Last edited by a moderator: Apr 20, 2017
    The following example should detect the Edition and automatically install the product key.
    Code:
    @ECHO OFF
    SETLOCAL
    (SET K="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion")
    (SET V="EditionID")
    (SET L=SLMGR.VBS /IPK)
    FOR /F "TOKENS=2*" %%A IN ('FINDSTR/B :: "%~f0"') DO (
    REG QUERY %K% /V %V%|FINDSTR/IE "%%A">NUL && (%L% %%B))
    
    :: Starter7Q28W-FT9PC-CMMYT-WHMY2-89M6G
    :: HomeBasicYGFVB-QTFXQ-3H233-PTWTJ-YRYRV
    :: HomePremiumRHPQ2-RMFJH-74XYM-BH4JX-XM76F
    :: ProfessionalHYF8J-CVRMY-CM74G-RPHKF-PW487
    :: UltimateD4F6K-QK3RD-TMVMJ-BBMRX-3MBMV
    :: StarterEBRQCV-K7HGQ-CKXP6-2XP7K-F233B
    :: HomeBasicEVTKM9-74GQY-K3W94-47DHV-FTXJY
    :: HomePremiumE76BRM-9Q4K3-QDJ48-FH4F3-9WT2R
    :: ProfessionalE3YHKG-DVQ27-RYRBX-JMPVM-WG38T
    :: UltimateETWMF7-M387V-XKW4Y-PVQQD-RK7C8
    :: StarterND4C3G-38HGY-HGQCV-QCWR8-97FFR
    :: HomeBasicNMD83G-H98CG-DXPYQ-Q8GCR-HM8X2
    :: HomePremiumND3PVQ-V7M4J-9Q9K3-GG4K3-F99JM
    :: ProfessionalNBKFRB-RTCT3-9HW44-FX3X8-M48M6
    :: UltimateNHTJK6-DXX8T-TVCR6-KDG67-97J8Q
    :: EnterpriseH7X92-3VPBB-Q799D-Y6JJ3-86WC6
    :: EnterpriseEH3V6Q-JKQJG-GKVK3-FDDRF-TCKVR
    :: EnterpriseNBQ4TH-BWRRY-424Y9-7PQX2-B4WBD
     
  5. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,068
    270
    #5 timesurfer, Mar 17, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thanks compo, what I have to do now is figure out how to write that into a .bat from IR7 into %systemdrive%

    And include the task delete and Key.bat delete

    :shisha:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,068
    270
    #6 timesurfer, Mar 17, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    In IR7 we currently use .vbs to set key and it does it silent at restart

    Using .bat still has the key installed windows message box pop up which will need to be eliminated

    Here is the .vbs stuff in green with the now unnecessary stuff in red that is used in last version

    Code:
    echo edition = CreateObject("WScript.Shell").RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\EditionID") >key.vbs
    echo Set keys = CreateObject ("Scripting.Dictionary") >>key.vbs
    echo keys.Add "Enterprise",                     "H7X92-3VPBB-Q799D-Y6JJ3-86WC6" >>key.vbs
    echo keys.Add "EnterpriseE",                    "H3V6Q-JKQJG-GKVK3-FDDRF-TCKVR" >>key.vbs
    echo keys.Add "EnterpriseN",                    "BQ4TH-BWRRY-424Y9-7PQX2-B4WBD" >>key.vbs
    echo keys.Add "HomeBasic",                      "YGFVB-QTFXQ-3H233-PTWTJ-YRYRV" >>key.vbs
    echo keys.Add "HomeBasicE",                     "VTKM9-74GQY-K3W94-47DHV-FTXJY" >>key.vbs
    echo keys.Add "HomeBasicN",                     "MD83G-H98CG-DXPYQ-Q8GCR-HM8X2" >>key.vbs
    echo keys.Add "HomePremium",                    "RHPQ2-RMFJH-74XYM-BH4JX-XM76F" >>key.vbs
    echo keys.Add "HomePremiumE",                   "76BRM-9Q4K3-QDJ48-FH4F3-9WT2R" >>key.vbs
    echo keys.Add "HomePremiumN",                   "D3PVQ-V7M4J-9Q9K3-GG4K3-F99JM" >>key.vbs
    echo keys.Add "Professional",                   "HYF8J-CVRMY-CM74G-RPHKF-PW487" >>key.vbs
    echo keys.Add "ProfessionalE",                  "3YHKG-DVQ27-RYRBX-JMPVM-WG38T" >>key.vbs
    echo keys.Add "ProfessionalN",                  "BKFRB-RTCT3-9HW44-FX3X8-M48M6" >>key.vbs
    echo keys.Add "Starter",                        "7Q28W-FT9PC-CMMYT-WHMY2-89M6G" >>key.vbs
    echo keys.Add "StarterE",                       "BRQCV-K7HGQ-CKXP6-2XP7K-F233B" >>key.vbs
    echo keys.Add "StarterN",                       "D4C3G-38HGY-HGQCV-QCWR8-97FFR" >>key.vbs
    echo keys.Add "Ultimate",                       "D4F6K-QK3RD-TMVMJ-BBMRX-3MBMV" >>key.vbs
    echo keys.Add "UltimateE",                      "TWMF7-M387V-XKW4Y-PVQQD-RK7C8" >>key.vbs
    echo keys.Add "UltimateN",                      "HTJK6-DXX8T-TVCR6-KDG67-97J8Q" >>key.vbs
    echo if keys.Exists(edition) then >>key.vbs
    echo WScript.Echo keys.Item(edition) >>key.vbs
    echo End If >>key.vbs
    FOR /F %%A in ('cscript /nologo key.vbs') do SET PIDKEY=%%A
    del key.vbs
    for /f "tokens=2 delims==" %%A in ('"wmic volume where SystemVolume="true" get DeviceId /format:list"') do set sd=%%A
    for /f "tokens=2 delims==" %%A in ('"wmic volume where DriveLetter="%SystemDrive%" get SerialNumber /format:list"') do set sn=%%A
    SET file=%sd%\IR7.bat
    echo @echo off>>%file% 
    echo echo Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")^>^>drive.vbs>>%file% 
    echo echo Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_Volume",,48)^>^>drive.vbs>>%file% 
    echo echo For Each objItem in colItems^>^>drive.vbs>>%file% 
    echo echo If Hex(%sn%) = Hex(objItem.SerialNumber) then^>^>drive.vbs>>%file% 
    echo echo Wscript.Echo objItem.DriveLetter^>^>drive.vbs>>%file% 
    echo echo End If ^>^>drive.vbs>>%file% 
    echo echo Next ^>^>drive.vbs>>%file% 
    echo for /f %%%%A IN ('"cscript /nologo drive.vbs"') do set dl=%%%%A>>%file% 
    echo :loop>>%file%
    echo if "%%dl:~-1%%"==" " set "dl=%%dl:~0,-1%%" ^& goto :loop>>%file%
    echo del drive.vbs>>%file% 
    echo reg load HKLM\MY_SYSTEM "%%dl%%\Windows\System32\config\system" ^>NUL >>%file% 
    echo reg delete HKLM\MY_SYSTEM\WPA /f ^>NUL >>%file% 
    echo reg unload HKLM\MY_SYSTEM ^>NUL >>%file%
    echo echo cscript /b slmgr.vbs /ipk %PIDKEY%^>%%dl%%\installkey.bat >>%file%
    echo echo del "C:\installkey.bat" ^>^>%%dl%%\installkey.bat >>%file%
    echo echo CreateObject("WScript.Shell").Run """C:\installkey.bat""", 0, False^>%%dl%%\key.vbs >>%file%
    echo echo @echo off ^>%%dl%%\launch.bat >>%file%
    echo echo wscript.exe "C:\key.vbs" ^>^>%%dl%%\launch.bat >>%file%
    echo echo del "%sd%\IR7.bat" ^>^>%%dl%%\launch.bat >>%file%
    echo echo del "C:\key.vbs" ^>^>%%dl%%\launch.bat >>%file%
    echo echo del "C:\launch.bat" ^>^>%%dl%%\launch.bat >>%file%
    echo reg load HKLM\MY_SOFTWARE "%%dl%%\Windows\System32\config\software" ^>NUL >>%file% 
    echo reg add HKLM\MY_SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v InstallKey /t REG_SZ /d C:\launch.bat /f ^>NUL >>%file%
    echo reg unload HKLM\MY_SOFTWARE >>%file%
    echo wpeutil reboot >>%file%
    It at restart like stated above does not show key has installed msg box

    This way IR7 will just need to restart then this Key.bat or Key.vbs will install key silently

    Perhaps what in this .vbs can still be utilized to put a Key.bat or Key.vbs to be run with task or with this code here

    Code:
    echo reg add HKLM\MY_SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v InstallKey /t REG_SZ /d C:\launch.bat /f ^>NUL >>%file%
    Any help anyone?

    Thanks

    TS
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. Compo

    Compo MDL Member

    Mar 29, 2011
    137
    104
    10
    #7 Compo, Mar 17, 2014
    Last edited by a moderator: Apr 20, 2017
    Why do you need to write the entire script to the host drive?

    Is it not sufficient to write the command alone, CSCRIPT /NOLOGO /B SLMGR.VBS /IPK XXXXX-XXXXX-XXXXX-XXXXX-XXXXX.
    Then just append the auto-delete to it.

    Code:
    @ECHO OFF
    SETLOCAL
    (SET K="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion")
    (SET V="EditionID")
    (SET L=CSCRIPT /NOLOGO /B SLMGR.VBS /IPK)
    (SET I="%SYSTEMDRIVE%\Key.bat")
    FOR /F "TOKENS=2*" %%A IN ('FINDSTR/B :: "%~f0"') DO (
    REG QUERY %K% /V %V%|FINDSTR/IE "%%A">NUL && (
    (ECHO=%L% %%B & ECHO=DEL %%0)>%I%))
    
    :: Starter7Q28W-FT9PC-CMMYT-WHMY2-89M6G
    :: HomeBasicYGFVB-QTFXQ-3H233-PTWTJ-YRYRV
    :: HomePremiumRHPQ2-RMFJH-74XYM-BH4JX-XM76F
    :: ProfessionalHYF8J-CVRMY-CM74G-RPHKF-PW487
    :: UltimateD4F6K-QK3RD-TMVMJ-BBMRX-3MBMV
    :: StarterEBRQCV-K7HGQ-CKXP6-2XP7K-F233B
    :: HomeBasicEVTKM9-74GQY-K3W94-47DHV-FTXJY
    :: HomePremiumE76BRM-9Q4K3-QDJ48-FH4F3-9WT2R
    :: ProfessionalE3YHKG-DVQ27-RYRBX-JMPVM-WG38T
    :: UltimateETWMF7-M387V-XKW4Y-PVQQD-RK7C8
    :: StarterND4C3G-38HGY-HGQCV-QCWR8-97FFR
    :: HomeBasicNMD83G-H98CG-DXPYQ-Q8GCR-HM8X2
    :: HomePremiumND3PVQ-V7M4J-9Q9K3-GG4K3-F99JM
    :: ProfessionalNBKFRB-RTCT3-9HW44-FX3X8-M48M6
    :: UltimateNHTJK6-DXX8T-TVCR6-KDG67-97J8Q
    :: EnterpriseH7X92-3VPBB-Q799D-Y6JJ3-86WC6
    :: EnterpriseEH3V6Q-JKQJG-GKVK3-FDDRF-TCKVR
    :: EnterpriseNBQ4TH-BWRRY-424Y9-7PQX2-B4WBD
     
  8. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,068
    270
    #8 timesurfer, Mar 17, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Ok,

    1. With IR7 we now can reset rearms without going into RE (Just requires restart)
    2. When you reset the rearms and after restart you need to install key! (Not before)
    3. When key installs we don't want successful key installation msg box to pop up!
    4. We also need to have key install at startup automatically via task or reg runonce
    5. Then key.bat needs to delete itself automatically and task if used needs to also be deleted
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,068
    270
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,068
    270
    Update :worthy:

    Thanks Compo, am trying to write it right now to %systemdrive%
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...