Batch/.CMD script to integrate ALL updates in offline image using DISM

Discussion in 'Windows 7' started by Paul_Black, Mar 11, 2018.

  1. Paul_Black

    Paul_Black MDL Novice

    Feb 20, 2018
    16
    1
    0
    Good evening, I am after some help on a clean install of Windows 7 SP1 x64 please!

    I have the folder: C:\Win7ISOUpdates which contains ALL the Windows updates (.msu) that I want to integrate into an offline image using DISM. I have numbers at the beginning of each of the updates so as they will be integrated in the numerical order specified.

    The offline image is stored in: C:\Win7ISO\OFFLine.

    First Attempt:

    I created a Notepad file in C:\Win7ISOUpdates called SlipStream.cmd.

    Within that file I used the command:
    For %%U in (*.msu) do Dism /Image:C:\Win7ISO\OFFLine /Add-Package /C:\Win7ISOUpdates:"%%U"

    I mounted the image: Dism /Mount-WIM /WimFile:C:\Win7ISO\sources\install.wim /Name:"Windows 7 HOMEPREMIUM" /MountDir:C:\Win7ISO\OFFLine

    I executed SlipStream.cmd in an elevated command prompt from within the C:\Win7ISOUpdates folder and got an error message saying: "The C option is not recognised in this context.".

    Second Attempt:

    Then I did a lot of research on the Internet about using a Batch file to accomplish this and this is what I came up with (I have never done this before so please don't laugh).

    I created a Batch file: SlipStream.bat
    Code:
    @Echo off
    ::Set Paths
    :
    :Path to the Mounted OFFLine Folder
    Set MOF=C:\Win7ISO\OFFLine
    :
    :Path to the folder with ALL Update Packages
    Set AUP=C:\Win7ISOUpdates
    :
    CLS
    dism /Image:%MOF% /Add-Package /PackagePath:%AUP%
    Echo ........................................
    Echo Update integration complete!
    Pause
    Exit
    Can anyone please tell me if this is correct?

    Thanks in advance.
     
  2. hearywarlot

    hearywarlot MDL Member

    Jul 31, 2015
    112
    153
    10
    Hello Paul_Black,
    The thing you want to do, creating a fully uptodate ISO of Windows 7 SP1 has already several easy to use and actively maintained solutions.

    There is a solution by Simplix from the OSZone forum:
    https://forums.mydigitallife.net/th...egrate-hotfixes-into-win7-distribution.45005/
    Simply download the latest executable, download Boss911's integrator archive and put the executable in the appropriate folder, then run the script and follow instructions.


    There is also Whdownloader by AlphaWaves for downloading the update packages:
    https://forums.mydigitallife.net/threads/whdownloader-download.66243/

    You have several easy to use scripts for slipstreaming the downloaded packages:
    MSMG's toolkit:
    https://forums.mydigitallife.net/threads/msmg-toolkit.50572/
    WHD-Windows7-Updates-Installer script by abbodi1406:
    https://forums.mydigitallife.net/threads/whdownloader-support-and-chat.44645/page-108#post-1296720

    Sorry for ignoring your question.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Paul_Black

    Paul_Black MDL Novice

    Feb 20, 2018
    16
    1
    0
    #3 Paul_Black, Mar 12, 2018
    Last edited: Mar 13, 2018
    (OP)
    Thanks for the reply hearywarlot, it is appreciated.

    There is indeed a lot of alternatives and useful information there, thank you.

    However, I really wanted to do this as a batch file.

    Thanks in advance.
     
  4. Paul_Black

    Paul_Black MDL Novice

    Feb 20, 2018
    16
    1
    0
    Good morning,

    Perhaps this will be easier to accomplish.

    Here is the setup (Windows 7 x64 with WAIK installed):

    C:\Win7ISO - Folder where the Win7ISO files have been extracted to.
    C:\Win7ISO\OFFLine - Folder used to mount the install.wim file.
    C:\Win7ISOUpdates - Folder where the updates (.msu) reside.
    C:\Win7ISOUpdated - Where the NEW ISO image will be saved into.

    How can I put the following into a Batch File and run it against a mounted offline install.wim file please?

    Step 1 (make the directory for the offline image):
    mkdir C:\Win7ISO\OFFLine

    Step 2 (mount the install.wim offline):
    Dism /Mount-WIM /WimFile:C:\Win7ISO\sources\install.wim /Name:"Windows 7 HOMEPREMIUM" /MountDir:C:\Win7ISO\OFFLine

    Step 3 (integrate ALL the updates in the C:\Win7ISOUpdates folder):
    For %U in (C:\Win7ISOUpdates\*.msu) do Dism /Image:C:\Win7ISO\OFFLine /Add-Package /PackagePath:%U

    Step 4 (unmount the offline image and commit all the changes made):
    Dism /Unmount-WIM /MountDir:C:\Win7ISO\OFFLine /Commit

    Step 5 (cleanup any leftovers):
    DISM /Cleanup-Wim

    Step 6 (delete the directory for the offline image which is now empty as it is not needed and so will not be included in the newly created ISO):
    DELETE C:\Win7ISO\OFFLine

    Step 7 (Create the new ISO):
    Oscdimg -bootdata:2#p0,e,bC:\Win7ISO\boot\etfsboot.com#pEF,e,bC:\Win7ISO\efi\microsoft\boot\Efisys.bin -u1 -udfver102 C:\Win7ISO C:\Win7ISOUpdated\Win7ISOUpdated.iso

    Thanks very much in advance.
     
  5. mehdibleu

    mehdibleu MDL Expert

    Jun 14, 2017
    1,009
    251
    60
    From the error message that you got ""The C option is not recognised in this context." , i think that the correct command would be :
    Dism /Image:"C:\Win7ISO\OFFLine" /Add-Package /PackagePath:"C:\Win7ISOUpdates"
     
  6. Paul_Black

    Paul_Black MDL Novice

    Feb 20, 2018
    16
    1
    0
    Thanks for the reply mehdibleu,

    I tried your suggestion (using 3 updates in the updates folder as a test) and it did indeed go through the 3 updates in the folder and said it completed successfully at the end.
    However, the updates bar showed 100% complete for update 1 but for the other 2 it only showed 97.7% complete for example.

    Thanks in advance.
     
  7. mehdibleu

    mehdibleu MDL Expert

    Jun 14, 2017
    1,009
    251
    60
    if you saw "the operation completed successfully" to appear, that means that all went smoothly and that the updates were integrated successfully.
     
  8. Paul_Black

    Paul_Black MDL Novice

    Feb 20, 2018
    16
    1
    0
    #8 Paul_Black, Mar 14, 2018
    Last edited: Mar 14, 2018
    (OP)
    Thanks for the reply mehdibleu,

    I have been trying to learn writing a Batch script and have come up with this called Test.bat (please let me know if I shouldn't run this before I do and muck anything up!):
    Code:
    @Echo off
    Title Create a new install.wim File!
    mkdir C:\Win7ISO\OFFLine
    Pause
    Echo Mounting...
    Dism /Mount-WIM /WimFile:C:\Win7ISO\sources\install.wim /Name:"Windows 7 HOMEPREMIUM" /MountDir:C:\Win7ISO\OFFLine
    Pause
    Echo Integrating updates...
    For %U in (C:\Win7ISOUpdates\*.msu) do Dism /Image:C:\Win7ISO\OFFLine /Add-Package /PackagePath:%U
    Pause
    Echo Un-mounting...
    Dism /Unmount-WIM /MountDir:C:\Win7ISO\OFFLine /Commit
    Pause
    Echo Cleaning up...
    DISM /Cleanup-Wim
    Pause
    Echo Deleting directory...
    rmdir C:\Win7ISO\OFFLine
    Pause
    Echo Creating ISO...
    Oscdimg -bootdata:2#p0,e,bC:\Win7ISO\boot\etfsboot.com#pEF,e,bC:\Win7ISO\efi\microsoft\boot\Efisys.bin -u1 -udfver102 C:\Win7ISO C:\Win7ISOUpdated\Win7ISOUpdated.iso
    Pause
    Exit
    Some questions please!

    (1) Where does the Batch file need to be run from (i.e. in what directory should I save the Batch file and then right click it and run it as Administrator)?
    EDIT: Or is the fact that I right click it and run it as Administrator enough?
    (2) How can I make sure that is uses an Elevated Command Prompt when running the script?
    (3) When creating the new ISO using Oscdimg it needs to be run from:
    Start > Microsoft Windows AIK > Right Click Deployment Tools Command Prompt > Run as Administrator
    How can I get it to do this please?

    I have put this together from investigation on many sites.

    Thanks in advance.
     
  9. Paul_Black

    Paul_Black MDL Novice

    Feb 20, 2018
    16
    1
    0
  10. mehdibleu

    mehdibleu MDL Expert

    Jun 14, 2017
    1,009
    251
    60
    #10 mehdibleu, Mar 15, 2018
    Last edited: Mar 15, 2018
    Sorry mate but i cannot help you much more with this, you will have to ask someone who is really good at programming so he can answers all your questions with detailed explanation.
    If i go by what you show about the batch file, i would say it's good enough but i would change some command lines :

    Code:
    @Echo off
    Title Create a new install.wim File!
    mkdir C:\Win7ISO\OFFLine
    Pause
    Echo Mounting...
    Dism /Mount-WIM /WimFile:C:\Win7ISO\sources\install.wim /Name:"Windows 7 HOMEPREMIUM" /MountDir:C:\Win7ISO\OFFLine
    Pause
    Echo Integrating updates...
    Dism /Image:"C:\Win7ISO\OFFLine" /Add-Package /PackagePath:"C:\Win7ISOUpdates" (assuming that you put the updates into the folder Win7ISOUpdates)
    Pause
    Echo Un-mounting...
    Dism /Unmount-WIM /MountDir:C:\Win7ISO\OFFLine /Commit
    Pause
    Echo Cleaning up...
    DISM /Cleanup-Wim
    Pause
    Echo Deleting directory...
    rmdir C:\Win7ISO\OFFLine
    Pause
    cd c:\tools
    Echo Creating ISO...
    Oscdimg -betfsboot.com -n -h c:\flat c:\windows7HomePremium.iso
    Pause
    Exit
    Before running the batch file, create a folder called C:\tools then go to Microsoft Windows AIK and find both of these files (oscdimg.exe and etfsboot.com) and put them into c:\tools
    Create a folder called c:\flat then extract your Windows 7 ISO and put the files in C:\flat

    Then run the batch file and see the result. (don't forget to remove
    assuming that you put the updates into the folder Win7ISOUpdates from the file)

    To test this, you can use VM, that'w what i do for all my tests, you can also test your batch configuration as well into VM.
     
  11. Paul_Black

    Paul_Black MDL Novice

    Feb 20, 2018
    16
    1
    0
    #11 Paul_Black, Mar 15, 2018
    Last edited: Mar 15, 2018
    (OP)
    Thanks for the reply mehdibleu, I will try out your suggestions later when I get home.

    I just thought I would come up with a few other ideas as well so I can try them too if they don't work.

    For the main part of the Batch script which needs to be run in an elevated command (Administrator):

    If I opened an elevated command prompt and then run the Batch file from there, would the commands inside the Batch file be run as Administrator?

    When I right clicked the .bat > Properties > Compatability, the Privilage Level for Run this program as an Administrator was greyed out!

    I then created a shortcut for the .bat file, I right clicked on it > Properties > Shortcut tab > Advanced > and checked Run as administrator. So am I assuming that this would now execute the Batch commands as an Administrator (except the oscdimg command obviously)?

    For the oscdimg part of the script which needs to be run in an elevated command (Administrator):

    Could I not put the full path to the oscdimg.exe C:\Program Files\Windows AIK\Tools\amd64\oscdimg.exe at the beginning of the command so it executes directly from the right directory?

    The reason I used...
    Oscdimg -bootdata:2#p0,e,bc:\Win7ISO\boot\etfsboot.com#pEF,e,bc:\Win7ISO\efi\microsoft\boot\Efisys.bin -u1 -udfver102 C:\Win7ISO C:\My.iso
    ...was so that it included efi support as well.

    I just want to have a few options for when I test it.
    My x64 computer is a few years old now and the BIOS doesn't have the Virtualisation facility so I can't test in a free x64 VM.

    Thanks in advance.

     
  12. mehdibleu

    mehdibleu MDL Expert

    Jun 14, 2017
    1,009
    251
    60
    #12 mehdibleu, Mar 15, 2018
    Last edited: Mar 15, 2018

    You can simply right click on the batch file then click on "run as administrator"

    No need to do this, again you can simply right click on the batch file then click on "run as administrator" and it should work.


    Yes that should does the job as well, you can simply test it and you will see the result.

    Again, i am not an expert, i just try to help as much as i can with the knowledge i have. If you want to have more detailted information about all this , you should contact someone as @abbodi1406 or @AnarethoS (both of these guys are great programmers, i'm sure they will answer all your questions )
     
  13. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    Regarding the admin elevation of a script there's no need to reinvent the wheel. Just check the existing script solutions here at MDL for the several ways to skin the cat :D.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. urie

    urie Moderator
    Staff Member

    May 21, 2007
    9,039
    3,388
    300
  15. Paul_Black

    Paul_Black MDL Novice

    Feb 20, 2018
    16
    1
    0
    Thanks for the link urie, it is very much appreciated.
    I will investigate those further.
    At least I know where to look now!
    Have a great weekend.
     
  16. Paul_Black

    Paul_Black MDL Novice

    Feb 20, 2018
    16
    1
    0
    #16 Paul_Black, Mar 16, 2018
    Last edited: Mar 16, 2018
    (OP)
    Good afternoon,

    I have managed to get EVERYTHING in the Batch file to run successfully EXCEPT the last part, the Oscdimg.

    I tried running it as one line and then I tried changing the directory and then running it.
    I have included the two screen shots of the results.

    I am almost there!

    Any help will be greatly appreciated.

    Thanks in advance.

    EDIT:
    I think I've cracked it...
    Code:
    cd C:\Program Files\Windows AIK\Tools\amd64\
     
    oscdimg.exe -bootdata:2#p0,e,bC:\Win7ISO\boot\etfsboot.com#pEF,e,bC:\Win7ISO\efi\microsoft\boot\Efisys.bin -u1 -udfver102 C:\Win7ISO C:\Win7ISOUpdated\Win7ISOUpdated.iso
     

    Attached Files:

  17. Paul_Black

    Paul_Black MDL Novice

    Feb 20, 2018
    16
    1
    0
    Good evening,

    Well everything went well.

    I have one small problem though.
    I run...
    Code:
    Dism /Image:"C:\Win7ISO\OFFLine" /Add-Package /PackagePath:"C:\Win7ISOUpdates"
    ...which when it finishes running shows the screenshot attachment below where it doesn't show 100%.

    Is there a way I can get it to wait for a few seconds after each update before it goes onto the next one so it can catch up please?

    Thanks in advance.
     

    Attached Files:

  18. mehdibleu

    mehdibleu MDL Expert

    Jun 14, 2017
    1,009
    251
    60
    As i said last time, no need to worry about the bar progress not reaching 100%, as long as you get the message "the operation completed successfully", that means that all the updates were integrated successfully.
     
  19. Enthousiast

    Enthousiast MDL Tester

    Oct 30, 2009
    47,287
    94,793
    450
    As long as it shows the " operation completed successfully" it's alright.
     
  20. mehdibleu

    mehdibleu MDL Expert

    Jun 14, 2017
    1,009
    251
    60
    it's already said from post just above yours :D