[.vbs] Can anyone write this .bat code in .vbs

Discussion in 'Scripting' started by timesurfer, Oct 26, 2013.

  1. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #1 timesurfer, Oct 26, 2013
    Last edited by a moderator: Apr 20, 2017
    Hi, I was curious can this .bat can be written in .vbs

    I think that some of it is unnecessary in .vbs in green but the rest should be possible!?

    Code:
    
    
    Code:
    @echo off 
    mode con: cols=42 lines=2 
    title IR7 
    setlocal ENABLEDELAYEDEXPANSION
    SETX IR7backup "%SystemDrive%\Trial\IR7" >nul 
    set KEY_NAME=HKCU\Software\Microsoft\Windows\CurrentVersion\Themes
    set VALUE_NAME=CurrentTheme
    set spp=SoftwareLicensingProduct
    for /F "usebackq tokens=3*" %%A IN (`reg query "%KEY_NAME%" /v "%VALUE_NAME%" 2^>nul ^| find "%VALUE_NAME%"`) do IF ~%%B==~ (SET themefile=%%A) ELSE (SET themefile=%%A %%B)
    for %%F in ("%themefile%") do set theme=%%~nF
    set wppath=%appdata%\Microsoft\Windows\Themes
    for /f "tokens=2,3,4,5,6,7 delims= " %%a in ('wmic os get caption') do set ver=%%a %%b %%c %%d %%e %%f 
    :loopV 
    if "%ver:~-1%"==" " set "ver=%ver:~0,-1%" & goto :loopV 
    wmic path %spp% get LicenseStatus /format:list 2>nul | findstr /i 5 >nul 2>&1 
    if %errorlevel%==0 call IR72.bat & goto :Exit 
    if %errorlevel%==1 goto :Backup 
    :Backup
    if "%ver%" == "Windows 7 Starter" ( goto :Exit ) 
    if "%ver%" == "Windows 7 Home Basic" ( goto :BackupHB ) 
    if exist "%systemdrive%\Trial\IR7\IR7Bkup.theme" del /s /q "%systemdrive%\Trial\IR7\IR7Bkup.theme" >nul
    echo F | xcopy "%themefile%" /s /q "%systemdrive%\Trial\IR7" /V /Y >nul 
    ren "%systemdrive%\Trial\IR7\%theme%.theme" "IR7Bkup.theme"
    goto :Exit 
    :BackupHB 
    copy "%wppath%\TranscodedWallpaper.jpg" /s /q "%systemdrive%\Trial\IR7" /Y >nul 
    goto :Exit 
    :Exit 
    ENDLOCAL 
    exit 
    
    Also .vbs doesn't run a console like .bat does correct? Meaning it runs silent for lack of better description in the folder it resides? If this is true then a task that runs a .vbs file wouldn't have to have to be set silent cause the .vbs doesn't open console like .bat does correct!? Thanks for any help :worthy:
     
  2. Mr Jinje

    Mr Jinje MDL Expert

    Aug 19, 2009
    1,770
    1,101
    60
    #2 Mr Jinje, Oct 26, 2013
    Last edited by a moderator: Apr 20, 2017
    re-write as vbs no thanks. But maybe have easier idea. Use the old invisible vbs to hide your bat window.

    http://superuser.com/questions/62525/run-a-completly-hidden-batch-file


     
  3. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #3 timesurfer, Oct 26, 2013
    Last edited: Oct 26, 2013
    (OP)
    Hi Mr Jinje, just to clarify why I have this question to re-write that short code into .vbs is a backup plan if this doesn't work with task

    My idea was that .vbs doesn't run as console so being hidden or not wouldn't be an issue like the IR7.bat is

    And I'm pretty sure the .vbs can call IR72.bat which does not have to run silent

    I just don't need IR7.bat to flash batch console at startup which just does backup and needs no interaction and IR72.bat only needs to run maybe once every 30 days if the regular 30 day rearm task was missed due to computer being off and 30 day rearm task couldn't run

    My goal is to have IR7 be silent so to speak unless something needs doing then if it does IR72.bat will run and rearm and restore theme/wallpaper

    IR7.bat run silent but must call IR72.bat when in notifications to rearm/restore theme/wallpaper
    IR72.bat not run silent

    Why I'm proposing the code be put in .vbs is because the silent running IR7.bat isn't calling IR72.bat and I'm not sure making it silent this way is going to call IR72.bat

    But if you tell me where to place the code in stuff I left here then I'll test...

    Thanks
     
  4. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #4 timesurfer, Oct 27, 2013
    Last edited: Oct 27, 2013
    (OP)
    Tested invisible.vbs

    It does the same thing that is happening now with task that runs IR7.bat silent!

    The invisible IR7.bat won't call IR72.bat so turning IR7.bat into IR7.vbs is the only solution as IR7.vbs will simply be run by basic task then easily call IR72.bat if in notifications and IR72.bat can do reaming/restoring theme/wallpaper

    Thanks
     
  5. Mr Jinje

    Mr Jinje MDL Expert

    Aug 19, 2009
    1,770
    1,101
    60
    what if we could call ir72.bat in a way so that it becomes visible.
     
  6. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #6 timesurfer, Oct 27, 2013
    Last edited: Oct 27, 2013
    (OP)
    I'm pretty sure IR72.bat is not the problem and always runs visible!? I think it's IR7.bat being hidden and not being able to do a call?!

    The .vbs fur sure could call IR72.bat correct?

    I can test any other ideas you have?

    Thanks :worthy:
     
  7. Mr Jinje

    Mr Jinje MDL Expert

    Aug 19, 2009
    1,770
    1,101
    60
    #7 Mr Jinje, Oct 27, 2013
    Last edited by a moderator: Apr 20, 2017
    I was thinking that even though IR7.bat is invisible, we could change the line.

    Code:
    if %errorlevel%==0 call IR72.bat & goto :Exit 
    if %errorlevel%==0 IR72.vbs & goto :Exit 
    
    and the IR72.vbs could use wscript to pop the IR72.bat visibly.

    Code:
    Set objShell = CreateObject("WScript.Shell")
    objShell.run("IR72.bat") 
     
  8. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #8 timesurfer, Oct 27, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Great idea but it didn't work with silent task when I ran task on demand

    When I clicked IR7.bat everything worked but again not with task

    Wish we had a .vbs wizard to help us out :worthy:...lol

    Thanks
     
  9. rrohela

    rrohela MDL Expert

    Sep 1, 2009
    1,612
    1,408
    60
    try by give absolute path to IR72.bat under hidden run....
     
  10. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #10 timesurfer, Oct 27, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Not sure what you mean?

    The cmdow cmd has a /hid but it still flashes at boot and we want silent not flash

    Can you explain in code or demonstrate please...

    @Mr Jinje

    I tried some task magic :p...lol

    Didn't work either :rolleyes:...lol

    IR7.bat

    Code:
    @echo off 
    mode con: cols=42 lines=2 
    title IR7 
    setlocal ENABLEDELAYEDEXPANSION 
    SETX IR7backup "%SystemDrive%\Trial\IR7" >nul 
    set KEY_NAME=HKCU\Software\Microsoft\Windows\CurrentVersion\Themes
    set VALUE_NAME=CurrentTheme
    set spp=SoftwareLicensingProduct
    for /F "usebackq tokens=3*" %%A IN (`reg query "%KEY_NAME%" /v "%VALUE_NAME%" 2^>nul ^| find "%VALUE_NAME%"`) do IF ~%%B==~ (SET themefile=%%A) ELSE (SET themefile=%%A %%B)
    for %%F in ("%themefile%") do set theme=%%~nF
    set wppath=%appdata%\Microsoft\Windows\Themes
    for /f "tokens=2,3,4,5,6,7 delims= " %%a in ('wmic os get caption') do set ver=%%a %%b %%c %%d %%e %%f 
    :loopV 
    if "%ver:~-1%"==" " set "ver=%ver:~0,-1%" & goto :loopV 
    wmic path %spp% get LicenseStatus /format:list 2>nul | findstr /i 5 >nul 2>&1 
    if %errorlevel%==0 goto :SecretTask 
    if %errorlevel%==1 goto :Backup 
    :SecretTask
    schtasks /create /tn "SecretTask" /tr "%systemdrive%\Trial\IR7\IR72.bat" /sc onlogon /rl highest /f
    schtasks /run /tn "SecretTask"
    goto exit
    :Backup
    if "%ver%" == "Windows 7 Starter" ( goto :Exit ) 
    if "%ver%" == "Windows 7 Home Basic" ( goto :BackupHB ) 
    if exist "%systemdrive%\Trial\IR7\IR7Bkup.theme" del /s /q "%systemdrive%\Trial\IR7\IR7Bkup.theme" >nul
    echo F | xcopy "%themefile%" /s /q "%systemdrive%\Trial\IR7" /V /Y >nul 
    ren "%systemdrive%\Trial\IR7\%theme%.theme" "IR7Bkup.theme"
    goto :Exit 
    :BackupHB 
    xcopy "%wppath%\TranscodedWallpaper.jpg" /s /q "%systemdrive%\Trial\IR7" /Y >nul 
    goto :Exit 
    :Exit 
    ENDLOCAL 
    exit 
    
    IR72.bat

    Code:
    @echo off 
    title IR7 
    schtasks /delete /tn "SecretTask" /f
    setlocal ENABLEDELAYEDEXPANSION 
    for /f "usebackq tokens=2 delims==" %%n in (`"%SystemRoot%\System32\wbem\WMIC.exe" /namespace:\\root\cimv2 path SoftwareLicensingService get RemainingWindowsReArmCount /format:list`) do set r=%%n 
    if %r% == 0 goto :Messagebox 
    mode con: cols=42 lines=2 
    cls 
    echo Rearming and Restoring Theme/Wallpaper...
    cscript.exe /b %windir%\system32\slmgr.vbs /rearm 
    net stop sppsvc >NUL 
    net start sppsvc >NUL 
    schtasks /create /tn "IR7" /tr "'%systemdrive%\Windows\system32\cmd.exe' /c cscript.exe /b %SystemDrive%\Windows\System32\slmgr.vbs /rearm && net stop sppsvc && net start sppsvc" /sc daily /mo 30 /ru "" /f >NUL  
    if "%ver%" == "Windows 7 Starter" ( goto :RestoreS ) 
    if "%ver%" == "Windows 7 Home Basic" ( goto :RestoreHB ) 
    echo F | xcopy "%systemdrive%\Trial\IR7\IR7Bkup.theme" /s /q "%windir%\resources\Themes" /V /Y >nul 
    echo Set WshShell = WScript.CreateObject("WScript.Shell") >>twrpwc.vbs 
    echo WshShell.Run "C:\Windows\\resources\\themes\\IR7Bkup.theme" >>twrpwc.vbs 
    echo Wscript.Sleep 10000 >>twrpwc.vbs 
    echo WshShell.AppActivate("Desktop Properties") >>twrpwc.vbs 
    echo WshShell.Sendkeys "%%FC" >>twrpwc.vbs 
    echo WshShell.Sendkeys "{F4}" >>twrpwc.vbs 
    call twrpwc.vbs 
    del twrpwc.vbs 
    reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Themes" /t REG_SZ /v CurrentTheme /d "%windir%\resources\Themes\IR7Bkup.theme" /f >NUL 
    goto :Exit 
    :RestoreS 
    title IR7 
    mode con: cols=28 lines=2 
    cls 
    echo Preparing logoff options...
    reg add "HKCU\Control Panel\Desktop" /f /v "Wallpaper" /d "%windir%\web\wallpaper\windows\img0.jpg" /t "REG_SZ" >nul 
    echo set args=WScript.Arguments >msgbox.vbs 
    echo wscript.quit MsgBox(Replace(Replace(args.item(1),"{cr}",vbNewLine,1,-1,1),"{qt}",Chr(34),1,-1,1),args.item(2),args.item(0)) >>msgbox.vbs 
    msgbox.vbs "IR7" "LOGOFF required. Log Off now?" 4 
    IF %ERRORLEVEL% EQU 6 del /s /q msgbox.vbs >nul && shutdown /l && call :Exit 
    IF %ERRORLEVEL% EQU 7 del /s /q msgbox.vbs >nul && call :Exit 
    cls 
    echo Preparing logoff options...
    :RestoreHB 
    title IR7 
    mode con: cols=28 lines=2 
    cls 
    echo Preparing logoff options...
    xcopy "%systemdrive%\Trial\IR7\TranscodedWallpaper.jpg" /s /q "%wppath%" /Y >nul 
    reg add "HKCU\Control Panel\Desktop" /f /v "Wallpaper" /d "%wppath%\TranscodedWallpaper.jpg" /t "REG_SZ" >nul 
    echo set args=WScript.Arguments >msgbox.vbs 
    echo wscript.quit MsgBox(Replace(Replace(args.item(1),"{cr}",vbNewLine,1,-1,1),"{qt}",Chr(34),1,-1,1),args.item(2),args.item(0)) >>msgbox.vbs 
    msgbox.vbs "IR7" "LOGOFF required. Log Off now?" 4 
    IF %ERRORLEVEL% EQU 6 del /s /q msgbox.vbs >nul && shutdown /l && call :Exit 
    IF %ERRORLEVEL% EQU 7 del /s /q msgbox.vbs >nul && call :Exit 
    :Messagebox
    title IR7 
    mode con: cols=41 lines=2 
    cls 
    echo Preparing reinstall/uninstall options...
    echo set args=WScript.Arguments >msgbox.vbs 
    echo wscript.quit MsgBox(Replace(Replace(args.item(1),"{cr}",vbNewLine,1,-1,1),"{qt}",Chr(34),1,-1,1),args.item(2),args.item(0)) >>msgbox.vbs  
    msgbox.vbs "IR7" "Your 180 day free trial has ended, do you wish to install IR7 again?" 4 
    IF %ERRORLEVEL% EQU 6 del /s /q msgbox.vbs >nul && call :ReinstallIR7
    IF %ERRORLEVEL% EQU 7 del /s /q msgbox.vbs >nul && call :UninstallIR7
    :UninstallIR7
    CLS 
    echo IR7 has been successfully uninstalled...
    REG  ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Activation" /v NotificationDisabled /t REG_DWORD /d 0 /f >NUL 
    schtasks /delete /tn "IR7" /f >NUL 
    schtasks /delete /tn "Hybrid2" /f >NUL 
    schtasks /query | FINDSTR /I "IORRT" >NUL 
    IF ERRORLEVEL 1 ( 
    GOTO TrialFolderDelete 
    ) ELSE ( 
    GOTO IR7FolderDelete 
    ) 
    :TrialFolderDelete
    echo rd /s /q C:\Trial >NUL >>C:\removeIR7.bat 
    echo schtasks /delete /tn "removeIR7" /f >NUL >>C:\removeIR7.bat 
    echo del /F /Q C:\removeIR7.bat >nul >>C:\removeIR7.bat 
    schtasks /create /tn "removeIR7" /tr >NUL "C:\removeIR7.bat" /sc onlogon /ru "" >NUL 
    schtasks /run /tn "removeIR7" >NUL 
    GOTO :Exit 
    :IR7FolderDelete
    echo rd /s /q C:\Trial\IR7 >NUL >>C:\removeIR7.bat 
    echo schtasks /delete /tn "removeIR7" /f >NUL >>C:\removeIR7.bat 
    echo del /F /Q C:\removeIR7.bat >nul >>C:\removeIR7.bat 
    schtasks /create /tn "removeIR7" /tr >NUL "C:\removeIR7.bat" /sc onlogon /ru "" >NUL 
    schtasks /run /tn "removeIR7" >NUL 
    GOTO :Exit 
    :ReinstallIR7
    echo Installing IR7...
    REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Activation" /v NotificationDisabled /t REG_DWORD /d 1 /f >NUL 
    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 "ServerDatacenter",               "7X29B-RDCR7-J6R29-K27FF-H9CR9" >>key.vbs 
    echo keys.Add "ServerDatacenterCore",           "7X29B-RDCR7-J6R29-K27FF-H9CR9" >>key.vbs 
    echo keys.Add "ServerEmbeddedSolution",         "M2KD2-F2333-Q3TJ8-BQMHX-9PWX6" >>key.vbs 
    echo keys.Add "ServerEmbeddedSolutionCore",     "M2KD2-F2333-Q3TJ8-BQMHX-9PWX6" >>key.vbs 
    echo keys.Add "ServerEnterprise",               "7P8GH-FV2FF-8FDCR-YK49D-D7P97" >>key.vbs 
    echo keys.Add "ServerEnterpriseCore",           "7P8GH-FV2FF-8FDCR-YK49D-D7P97" >>key.vbs 
    echo keys.Add "ServerEnterpriseIA64",           "7YKJ4-CX8QP-Q23QY-7BYQM-H2893" >>key.vbs 
    echo keys.Add "ServerEssentialAdditional",      "7PDBG-28HK4-276G6-XVJF4-KH9Y4" >>key.vbs 
    echo keys.Add "ServerEssentialAdditionalSvc",   "RCDPD-97Q7B-MRDC3-GTRYF-MCD6G" >>key.vbs 
    echo keys.Add "ServerEssentialManagement",      "4F37J-4YTKY-6DFDJ-FDRFY-2HT34" >>key.vbs 
    echo keys.Add "ServerEssentialManagementSvc",   "4HFV2-KB9P6-TQVJF-87D8X-2YYBF" >>key.vbs 
    echo keys.Add "ServerForSBSolutions",           "PHYFD-HQ4XW-78PR4-2CXKF-V67KJ" >>key.vbs 
    echo keys.Add "ServerForSBSolutionsEM",         "JR4Y2-WC84X-PBRDJ-QTBTB-TQGGH" >>key.vbs 
    echo keys.Add "ServerHomePremium",              "4BWDV-9MKGX-V9QJ4-YWFWR-P6974" >>key.vbs 
    echo keys.Add "ServerHomeStandard",             "MCQYD-2TJYQ-JP7KR-7GYYF-YGPXQ" >>key.vbs 
    echo keys.Add "ServerHPC",                      "Q7PRR-M2WBM-RJJ99-FG393-MGY3B" >>key.vbs 
    echo keys.Add "ServerHyperCore",                "Q8R8C-T2W6H-7MGPB-4CQ9R-KR36H" >>key.vbs 
    echo keys.Add "ServerMediumBusinessManagement", "FD499-FD79G-V9D2W-F9WQ6-MD2VC" >>key.vbs 
    echo keys.Add "ServerMediumBusinessMessaging",  "YVYC7-KVQ8G-XF6K4-9MG8M-QXFC2" >>key.vbs 
    echo keys.Add "ServerMediumBusinessSecurity",   "YQ3V7-79DM4-42PVW-BYRH8-69VXK" >>key.vbs 
    echo keys.Add "ServerSBSPremium",               "BXQQP-Q6Q6D-TR7TR-3YXQW-VFHKM" >>key.vbs 
    echo keys.Add "ServerSBSPremiumCore",           "BXQQP-Q6Q6D-TR7TR-3YXQW-VFHKM" >>key.vbs 
    echo keys.Add "ServerSBSStandard",              "YMFM8-J2RV2-66G78-XPQ7C-4RY3B" >>key.vbs 
    echo keys.Add "ServerSolution",                 "Y7GVM-YFQQW-HV8HW-GRW6D-YJ84M" >>key.vbs 
    echo keys.Add "ServerSolutionEM",               "WF9T8-VT7D2-GD629-WTKGH-3WBJT" >>key.vbs 
    echo keys.Add "ServerSolutionsPremium",         "4TMY4-8JG4B-VKY8X-6TVDH-J7XFV" >>key.vbs 
    echo keys.Add "ServerSolutionsPremiumCore",     "4TMY4-8JG4B-VKY8X-6TVDH-J7XFV" >>key.vbs 
    echo keys.Add "ServerStandard",                 "HMG6P-C7VGP-47GJ9-TWBD4-2YYCD" >>key.vbs 
    echo keys.Add "ServerStandardCore",             "HMG6P-C7VGP-47GJ9-TWBD4-2YYCD" >>key.vbs 
    echo keys.Add "ServerWeb",                      "YGTGP-9XH8D-8BVGY-BVK4V-3CPRF" >>key.vbs 
    echo keys.Add "ServerWebCore",                  "YGTGP-9XH8D-8BVGY-BVK4V-3CPRF" >>key.vbs 
    echo keys.Add "ServerWinFoundation",            "36RXV-4Y4PJ-B7DWH-XY4VW-KQXDQ" >>key.vbs 
    echo keys.Add "ServerWinSB",                    "JG43G-CMPHG-VPBC6-9TDQR-RRFJ4" >>key.vbs 
    echo keys.Add "ServerWinSBV",                   "WQG3Q-VWT72-VX39Q-VRTRD-2RF7K" >>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 keys.Add "Embedded",                       "743Q4-G676P-84RX9-B8HRR-6V73F" >>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 slmgr.vbs /dlv ^>^>%%dl%%\installkey.bat >>%file% 
    if "%ver%" == "Windows 7 Starter" ( goto :WriteS ) 
    if "%ver%" == "Windows 7 Home Basic" ( goto :WriteHB ) 
    echo echo xcopy "%%%%systemdrive%%%%\Trial\IR7\IR7Bkup.theme" /s /q "%%%%windir%%%%\resources\Themes" /Y /V ^^^>null^>^>%%dl%%\installkey.bat >>%file%  
    echo Set WshShell = WScript.CreateObject("WScript.Shell") >>twrpwc.vbs 
    echo WshShell.Run "C:\Windows\\resources\\themes\\IR7Bkup.theme" >>twrpwc.vbs 
    echo Wscript.Sleep 10000 >>twrpwc.vbs 
    echo WshShell.AppActivate("Desktop Properties") >>twrpwc.vbs 
    echo WshShell.Sendkeys "%%FC" >>twrpwc.vbs 
    echo WshShell.Sendkeys "{F4}" >>twrpwc.vbs 
    call twrpwc.vbs 
    del twrpwc.vbs 
    :ResumeIR7 
    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% 
    reagentc /boottore >NUL 
    echo Windows is restarting now... 
    schtasks /create /tn "IR7" /tr "'%SystemDrive%\Windows\system32\cmd.exe' /c cscript.exe /b C:\Windows\System32\slmgr.vbs /rearm && net stop sppsvc && net start sppsvc" /sc daily /mo 30 /ru "" /f >nul  
    shutdown.exe /r /t 0 
    GOTO :Exit 
    :Exit 
    ENDLOCAL 
    exit 
    :WriteS 
    mode con: cols=28 lines=2 
    cls 
    echo Preparing logoff options...
    echo echo reg add "HKCU\Control Panel\Desktop" /f /v "Wallpaper" /d "%%%%windir%%%%\web\wallpaper\windows\img0.jpg" /t "REG_SZ" ^^^>nul ^>^>%%dl%%\installkey.bat >>%file%  
    echo echo echo set args=WScript.Arguments ^^^>msgbox.vbs^>^>%%dl%%\installkey.bat >>%file%   
    echo echo echo wscript.quit MsgBox(Replace(Replace(args.item(1),"{cr}",vbNewLine,1,-1,1),"{qt}",Chr(34),1,-1,1),args.item(2),args.item(0)) ^^^>^^^>msgbox.vbs ^>^>%%dl%%\installkey.bat >>%file%  
    echo echo msgbox.vbs "IR7" "LOGOFF required. Log Off now?" 4 ^>^>%%dl%%\installkey.bat >>%file%  
    echo echo IF %%%%ERRORLEVEL%%%% EQU 6 del /s /q msgbox.vbs ^^^>nul ^^^& shutdown /l ^^^& call :Exit ^>^>%%dl%%installkey.bat >>%file% 
    echo echo IF %%%%ERRORLEVEL%%%% EQU 7 del /s /q msgbox.vbs ^^^>nul ^^^& call :Exit ^>^>%%dl%%\installkey.bat >>%file% 
    goto :ResumeIR7 
    :WriteHB 
    mode con: cols=28 lines=2 
    cls 
    echo Preparing logoff options...
    echo echo xcopy "%%%%systemdrive%%%%\Trial\IR7\TranscodedWallpaper.jpg" /s /q "%wppath%" /Y ^^^>nul ^>^>%%dl%%\installkey.bat >>%file% 
    echo echo reg add "HKCU\Control Panel\Desktop" /f /v "Wallpaper" /d "%wppath%\TranscodedWallpaper.jpg" /t "REG_SZ" ^^^>nul ^>^>%%dl%%\installkey.bat >>%file%  
    echo echo echo set args=WScript.Arguments ^^^>msgbox.vbs ^>^>%%dl%%\installkey.bat >>%file% 
    echo echo echo wscript.quit MsgBox(Replace(Replace(args.item(1),"{cr}",vbNewLine,1,-1,1),"{qt}",Chr(34),1,-1,1),args.item(2),args.item(0)) ^^^>^^^>msgbox.vbs ^>^>%%dl%%\installkey.bat >>%file% 
    echo echo msgbox.vbs "IR7" "LOGOFF required. Log Off now?" 4 ^>^>%%dl%%\installkey.bat >>%file% 
    echo echo IF %%%%ERRORLEVEL%%%% EQU 6 del /s /q msgbox.vbs ^^^>nul ^^^& shutdown /l ^^^& call :Exit ^>^>%%dl%%\installkey.bat >>%file%  
    echo echo IF %%%%ERRORLEVEL%%%% EQU 7 del /s /q msgbox.vbs ^^^>nul ^^^& call :Exit ^>^>%%dl%%\installkey.bat >>%file% 
    goto :ResumeIR7 
    
     
  11. rrohela

    rrohela MDL Expert

    Sep 1, 2009
    1,612
    1,408
    60
    #11 rrohela, Oct 27, 2013
    Last edited by a moderator: Apr 20, 2017
    I am just saying to give complete path to batch file
    Code:
    
    if %errorlevel%==0 call "d:\foler\folder\IR72.bat" & goto :Exit
    
    
    Code:
    
    CALL [drive:][path]filename [batch-parameters]
    
    
     
  12. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #12 timesurfer, Oct 27, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thanks I will test that...

    @Mr Jinje

    I have another idea, I could combine IR7.bat with IR72.bat like it was originally before I split it, then do a .vbs that checks if in notifications

    Here is the wmic class "LicenseStatus"

    Code:
    echo wmic path %%SoftwareLicensingProduct%% get LicenseStatus /format:list 2^>nul ^| findstr /i 5
    Just need to code it for .vbs

    Then if value is 5 or notifications then run with this code all in a .vbs

    Code:
    set WSHShell = CreateObject("WScript.Shell")
    WSHShell.Run "IR7.bat", 1, True
    The goal is to:

    1. Detect if in notifications
    2. If in notifications then run IR7.bat which is now both IR7.bat and IR72.bat combined or maybe leave them seperate
    3. Use a "normal task" to run IR7.vbs that calls IR7.bat

    This way IR7.vbs runs silent, does the notification check and exits if not in notifications :eek: ...lol

    Thus things are silent for user until they are in notifications
     
  13. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #13 timesurfer, Oct 27, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    @Mr Jinje

    Or can you write a .ps1 file?

    Code:
    PS C:\> .\IR7.ps1
    Will I be able to write a .ps1 from a batch?

    Definitely can write an .vbs from batch!

    Code:
    Query if in notifications (5)
    If not true goto exit
    If true
    run IR7.bat
    exit
    
    I know this is not powershell code just giving example :p...lol

    For .vbs I got this:

    Code:
    set WSHShell = CreateObject("WScript.Shell")
    wmic path %SoftwareLicensingProduct% get LicenseStatus /format:list  findstr /i 5
    If Err.Number <> 0 Then
    WSHShell.Run "1.bat", 1, True
    WScript.Quit
    Else
    WScript.Quit
    I also know this is not correct just saying :p...lol

    Whatever we do needs task to run it so that is calls IR7.bat

    I think we're close :suicide:
     
  14. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #14 timesurfer, Oct 27, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Just found this for powershell given that a task will run a .ps1 file and that a .ps1 file can call IR7.bat

    https://blogs.technet.com/b/heyscri...-setting-the-license-key.aspx?Redirected=true

    Code:
    Get-WmiObject SoftwareLicensingProduct |
    
    select Name, LicenseStatus
    https://social.technet.microsoft.co...indows-activation-status-with-powershell.aspx

    Code:
    # set up the different possible types of licenses in an array:
    
    #
    
    $licenseStatus=@{0="Unlicensed"; 1="Licensed"; 2="OOBGrace"; 3="OOTGrace";
    
                    4="NonGenuineGrace"; 5="Notification"; 6="ExtendedGrace"}
    
    #
    
    # Now get the license details and assign the object to $r
    
    #
    
    $r=Get-CimInstance -Class SoftwareLicensingProduct `
    
     |Where {$_.ApplicationID -eq "55c92734-d682-4d71-983e-d6ec3f16059f" -AND $_.PartialProductKey -ne $null}
    
    #
    
    #  Now apply the value of $r.LicenseStatus to the $licenseStatus array
    
    Write-Host $licenseStatus[[int]$r.LicenseStatus]
    
    # You could equally well return this as a value from a function...


    Code:
    function Get-ActivationStatus {
    [CmdletBinding()]
        param(
            [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
            [string]$DNSHostName = $Env:COMPUTERNAME
        )
        process {
            try {
                $wpa = Get-WmiObject SoftwareLicensingProduct -ComputerName $DNSHostName `
                -Filter "ApplicationID = '55c92734-d682-4d71-983e-d6ec3f16059f'" `
                -Property LicenseStatus -ErrorAction Stop
            } catch {
                $status = New-Object ComponentModel.Win32Exception ($_.Exception.ErrorCode)
                $wpa = $null    
            }
            $out = New-Object psobject -Property @{
                ComputerName = $DNSHostName;
                Status = [string]::Empty;
            }
            if ($wpa) {
                :outer foreach($item in $wpa) {
                    switch ($item.LicenseStatus) {
                        0 {$out.Status = "Unlicensed"}
                        1 {$out.Status = "Licensed"; break outer}
                        2 {$out.Status = "Out-Of-Box Grace Period"; break outer}
                        3 {$out.Status = "Out-Of-Tolerance Grace Period"; break outer}
                        4 {$out.Status = "Non-Genuine Grace Period"; break outer}
                        5 {$out.Status = "Notification"; break outer}
                        6 {$out.Status = "Extended Grace"; break outer}
                        default {$out.Status = "Unknown value"}
                    }
                }
            } else {$out.Status = $status.Message}
            $out
        }
    }
    Code:
    strComputer = "." 
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
    Set colItems = objWMIService.ExecQuery( _
        "SELECT * FROM SoftwareLicensingProduct WHERE LicenseStatus = 0",,48) 
    For Each objItem in colItems 
        Wscript.Echo "-----------------------------------"
        Wscript.Echo "SoftwareLicensingProduct instance"
        Wscript.Echo "-----------------------------------"
        Wscript.Echo "LicenseStatus: " & objItem.LicenseStatus
    Next
    Code:
    Set objWMIService = GetObject(“winmgmts:\\.\root\cimv2″)
    Set colItems = objWMIService.ExecQuery(“Select * From SoftwareLicensingProduct”)
    Coltest = int(0)
    bWinActivated = False
    
    For Each objitem In colItems
    WScript.Echo objItem.Description
    WScript.Echo “License Status: “& objitem.LicenseStatus
    WScript.Echo objitem.GracePeriodRemaining
    WScript.Echo “KeyManagementServiceProductKeyID: “&objitem.KeyManagementServiceProductKeyID
    IF int(objitem.LicenseStatus) 0 Then
    
    bWinActivated = True
    strActivationType = objItem.Description
    strKey = “ProductKey:” & objItem.ProductKeyID
    
    End if
    Next
    If bWinActivated = False Then MsgBox(“Windows is not activated”)
    If bWinActivated = True Then
    MsgBox(“Windows is activated using “&strActivationType& ” key.” & strKey)
    End if
     

    Attached Files:

  15. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #15 timesurfer, Oct 28, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Did some testing and silent .bat and .vbs don't call/run anything :eek:

    Also it won't do to just combine IR7.bat and IR72.bat cause IR7.bat still needs to do set and backuup stuff so ideally someone capable needs to write the IR7.bat codes into IR7.vbs and a task will be needed to run IR7.vbs at onlogon

    Assuming a task will run IR7.vbs this is how my backup/restore concept will work best

    Otherwise the best I can think of doing for the moment is to create a task that uses the start /min cmd to run IR7.bat in task bar which is kinda silent :suicide:...lol

    But I don't know how to write a task with "start /min"

    Here is the IR7.bat if anyone want's to re-write it in .vbs

    Code:
    @echo off 
    mode con: cols=42 lines=2 
    title IR7 
    setlocal ENABLEDELAYEDEXPANSION
    SETX IR7backup "%SystemDrive%\Trial\IR7" >nul 
    set KEY_NAME=HKCU\Software\Microsoft\Windows\CurrentVersion\Themes
    set VALUE_NAME=CurrentTheme
    set spp=SoftwareLicensingProduct
    for /F "usebackq tokens=3*" %%A IN (`reg query "%KEY_NAME%" /v "%VALUE_NAME%" 2^>nul ^| find "%VALUE_NAME%"`) do IF ~%%B==~ (SET themefile=%%A) ELSE (SET themefile=%%A %%B)
    for %%F in ("%themefile%") do set theme=%%~nF
    set wppath=%appdata%\Microsoft\Windows\Themes
    for /f "tokens=2,3,4,5,6,7 delims= " %%a in ('wmic os get caption') do set ver=%%a %%b %%c %%d %%e %%f 
    :loopV 
    if "%ver:~-1%"==" " set "ver=%ver:~0,-1%" & goto :loopV 
    wmic path %spp% get LicenseStatus /format:list 2>nul | findstr /i 5 >nul 2>&1 
    if %errorlevel%==0 call IR72.bat & goto :Exit 
    if %errorlevel%==1 goto :Backup 
    :Backup
    if "%ver%" == "Windows 7 Starter" ( goto :Exit ) 
    if "%ver%" == "Windows 7 Home Basic" ( goto :BackupHB ) 
    if exist "%systemdrive%\Trial\IR7\IR7Bkup.theme" del /s /q "%systemdrive%\Trial\IR7\IR7Bkup.theme" >nul
    echo F | xcopy "%themefile%" /s /q "%systemdrive%\Trial\IR7" /V /Y >nul 
    ren "%systemdrive%\Trial\IR7\%theme%.theme" "IR7Bkup.theme"
    goto :Exit 
    :BackupHB 
    copy "%wppath%\TranscodedWallpaper.jpg" /s /q "%systemdrive%\Trial\IR7" /Y >nul 
    goto :Exit 
    :Exit 
    ENDLOCAL 
    exit 
    
     
  16. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #16 timesurfer, Oct 31, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    [solved]

    Code:
    echo CreateObject("Wscript.Shell").Run "%systemdrive%\Trial\IR7\IR7.bat",0,True >>%SystemDrive%\Trial\IR7\IR7.vbs