[Batch] My own general inability

Discussion in 'Scripting' started by Humphrey, Apr 7, 2014.

  1. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    Yep, that's indeed the most foolproof way so far :good3:. That way i run adk 8.1.1 in Win 7 :cool2:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,466
    990
    60

    Thanks guys. I will have to write that into the script when I get back home.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,964
    907
    60
    #23 Flipp3r, Apr 22, 2014
    Last edited by a moderator: Apr 20, 2017
    Saw the issues with dism path. My old batch for win7 had
    Code:
    set DISM="C:\Program Files\Windows OPK\Tools\%processor_architecture%\Servicing\dism.exe"
    Just change the path to your ADK...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,466
    990
    60
    #24 Humphrey, Apr 23, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thanks for your input Flipp3r, how ever I am sure my SET lines are correct.
    If you'd like, try the script and play around with it. ATM I am just going an easier route till I get a little further into this batch.

    Here is the current script, it is incomplete, messy and doesn't function correctly.
    Code:
    @echo off
    mode con cols=87 lines=50
    setlocal ENABLEDELAYEDEXPANSION
    TITLE Humphrey's %~nx0
    CD /D %~dp0
    IF NOT EXIST "WorkDir" MD WorkDir & MD WorkDir\Mount & MD WorkDir\Images & MD WorkDir\ISO
    SET inputfile=%1%
    SET WorkDir=.\WorkDir
    SET MountDir=!WorkDir!\Mount
    SET ISO=!WorkDir!\ISO
    SET Images=!WorkDir!\Images
    
    IF "%~1"=="" CLS & GOTO :Check
    IF "%~1"=="/check" GOTO :TEST
    IF "%~n1"=="WorkDir" GOTO :Credit
    
    
    :Check
    IF /i not "%~x1"==".wim" ( 
        TITLE How to use %~nx0
        ECHO.
        ECHO. ===============================================
        ECHO.                  Instructions
        ECHO. ===============================================
        ECHO.
        ECHO. %~nx0 is meant for modifiying WIM files and must 
        ECHO. have a .WIM file dropped onto it.  
        ECHO.
        ECHO. Drag and drop an Install.wim onto %~nx0.
        ECHO.
        ECHO.
        ECHO. File: !inputfile! is NOT a WIM file. 
        ECHO. Drop one onto %~nx0 to proceed.&PAUSE >NUL&EXIT
    ) ELSE (
        GOTO :DISMCheck
    )
    
    
    :DISMCheck
    @(NET FILE||(powershell -command Start-Process '%0' -Verb runAs -ArgumentList '%* '&EXIT /B))>NUL 2>&1
    
    CALL "C:\Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat"
    
    ECHO.!DISM!
    PAUSE
    goto :skip1
    
    
    
    
    
    :: Checks for and sets DISM.
    IF "%PROCESSOR_ARCHITECTURE%"=="AMD64" (SET _ProF=!ProgramFiles^(x86^)!) ELSE (SET _ProF=!ProgramFiles!)
    SET DISM="!_ProF!\Windows Kits\8.1\Assessment and Deployment Kit\Deployment Tools\!PROCESSOR_ARCHITECTURE!\DISM\DISM.exe"
    
    IF EXIST !DISM! (
        GOTO :GetAdmin
    ) ELSE (
        ECHO.
        ECHO.!DISM!
        ECHO.
        ECHO. Couldn't locate DISM. Download and install the
        ECHO. Windows 8.1 ADK for %~nx0 functionality.
        ECHO.
        SET /P altdism=Alternatively, drag and drop Dism.exe here: 
        ECHO.
        IF EXIST "!altdism!" (
            SET DISM=!altdism!
            GOTO :GetAdmin
        ) ELSE (
            CLS&GOTO :DISMCheck
        )
    )
    
    
    :GetAdmin
    :: Request administrative permission.
    :: @(NET FILE||(powershell -command Start-Process '%0' -Verb runAs -ArgumentList '%* '&EXIT /B))>NUL 2>&1
    
    
    
    :CommandCenter
    ECHO.
    ECHO. 
    ECHO. ===============================================
    ECHO.                  DISM Commands
    ECHO. ===============================================
    ECHO.
    ECHO. [0] Mount %~nx1    [1] Unmount !MountDir!
    ECHO. [2] Get %~nx1 info [3] Get !MountDir! info
    ECHO. [4] Cleanup Mounts       [5] Settings
    ECHO. [6] Exit
    ECHO.
    choice /C 0123456789 /N /M "Select menu item:"
    if !ERRORLEVEL! EQU 1 CLS & GOTO :Mount
    if !ERRORLEVEL! EQU 2 CLS & GOTO :UnMount
    if !ERRORLEVEL! EQU 3 CLS & !DISM! /Get-ImageInfo /ImageFile:%~nx1
    if !ERRORLEVEL! EQU 4 ECHO. UnderConstruction
    if !ERRORLEVEL! EQU 5 CLS & !DISM! /Cleanup-Mountpoints
    if !errorlevel! equ 6 CLS & GOTO :DISMSETTINGS
    if !ERRORLEVEL! EQU 7 PAUSE
    GOTO :CommandCenter    
    
    
    :Mount
    !DISM! !Logged! /Get-ImageInfo /ImageFile:!inputfile!
    ECHO.
    SET /P Index= Which index?: 
    CLS
    !DISM! /Mount-wim /wimfile:!inputfile! /Index:!INDEX! /Mountdir:!MountDir! 
    :: ECHO.
    :: ECHO. Gathering some info.
    :: For /F "Tokens=1,2* Delims=: " %%A In (
    ::     '"!DISM!" /Image:!mountdir! /Get-CurrentEdition') Do (
    ::     If %%A Equ Version Set VER=%%B
    ::     If %%B Equ Edition Set currentedition=%%C
    ::     )
    GOTO :CommandCenter    
    
    
    :UnMount
    ECHO.
    choice /C YN /M " Save to %~nx1 ?: "
    if !ERRORLEVEL! EQU 1 SET SAVE=/Commit
    if !ERRORLEVEL! EQU 2 SET SAVE=/Discard
    !DISM! /UNMount-wim /Mountdir:!MountDir! !SAVE!
    GOTO :CommandCenter    
    
    
    :DismSettings
    ECHO.
    ECHO. ===============================================
    ECHO.                 DISM Settings
    ECHO. ===============================================
    ECHO.
    ECHO. [0] Delete DISM Logs  [1] Change Log Level
    ECHO. [2] 
    ECHO.
    choice /C 01 /N /M "Select menu item:"
    if !ERRORLEVEL! EQU 1 DEL /F /Q "%WINDIR%\Logs\Dism\dism.log" & DEL /F /Q "!WorkDir!\DISM.log"
    IF !ERRORLEVEL! EQU 2 CLS & GOTO :LogLvl
    
    CLS & GOTO :DISMSETTINGS
    
    
    :LogLvl
    ECHO.
    ECHO. 1 = Errors only
    ECHO. 2 = Errors and warnings
    ECHO. 3 = Errors, warnings, and informational
    ECHO. 4 = All of the information listed previously, plus debug output 
    ECHO. 5 = Back
    ECHO.
    SET /P _loglvl= 1-5?: 
    IF "!_loglvl!"=="5" CLS & GOTO :DISMSETTINGS
    SET "Logged=/LogPath:!WorkDir!\DISM.log /LogLevel:!_loglvl!"
    GOTO :DismSettings
    
    :SelfCheck
    ECHO.
    ECHO. ===============================================
    ECHO.                 Self Diagnosis
    ECHO. ===============================================
    ECHO.
    ECHO. DISM.exe: !DISM!
    ECHO. Input file: !inputfile!
    ECHO. Work Dir: !WorkDir!
    ECHO. Mount Dir:!MountDir!
    ECHO. ISO: !ISO!
    ECHO. Images: !Images!
    ECHO.
    PAUSE &GOTO :EOF
    :Credit
    :: People that assisted in the creation of this batch file.
    TITLE Credit is due.
    ECHO. ===============================================
    ECHO.               Special Thanks To
    ECHO. ===============================================
    ECHO.
    ECHO. BetonMAN - Amazing admin prompt.
    ECHO.
    ECHO. Compo - General scripting assistance.
    ECHO.
    ECHO. s1ave77 - General scripting assistance.
    ECHO.
    PAUSE >NUL & GOTO :EOF
    
    
    :EOF
    exit /b
    
    :TEST
    CLS
    ECHO. WORKS
    pause
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,466
    990
    60
    I am rewriting the batch using a method I haven't used before. Going to be a while before I will post it probably but we'll see.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,466
    990
    60
    So HERE that rewrite is. About as unfinished as the first version was but it is on the way.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...