Batch file for automated custom DISM package removals.

Discussion in 'Scripting' started by lewcass, Jun 12, 2018.

  1. lewcass

    lewcass MDL Senior Member

    Mar 10, 2018
    429
    251
    10
    I recently started working with batch files and although i dont understand what does what yet i know what works for what even though i dont understand why, things just work.

    I have opened some bat and cmd files from around the web and some from projects here at mdl.I have done some work with msmg package removal list feature and want to combine most of the removals he has in the menus with telemetry package removals plus some features i will never use.

    I have done some removals with the cbsenum tool too so i know that packages will need to be unhidden and decoupled. This is the part that i think i may get into trouble with because i cant see in the msmg tool how to unhide and decouple things, i know this is done in the registry. I can track those registry changes on a running system with RegFromApp, export that reg file then apply it to a mounted image/registry hive.

    I would rather not use that install wim tweak tool, i have seen warnings about it.

    Is this possible?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. lewcass

    lewcass MDL Senior Member

    Mar 10, 2018
    429
    251
    10
    #2 lewcass, Jun 12, 2018
    Last edited: Jun 13, 2018
    (OP)
    I have gone through pages 1 to 20 of the scripting section and i think i have found what i need. :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    534
    926
    30
    My recommendation is to use not use any script that uses an executable to perform silent commands unless it's explicitly stated what exactly said executable is doing, why an executable is required for such commands and uses proper error-catching. I will create a PowerShell executable with a silent process only to ensure strict error-handling, method and API control. For example, one of my executable files converts an image to Windows 10 Pro for Workstations, and uses a C# method to access, convert and release the image's internal XMDocument representation. It does this for a very specific reason, that I have documented on both GitHub, PowerShellGet and the official PowerShell Repository:

    By creating an executable, and using P/Invoke and SafeHandle sealed classes with official Microsoft APIs, I can mitigate any potential interactions with additional processes running on a system that could corrupt, or hinder, the process the executable is performing.

    Conversely, some scripts you have to be very careful of, particularly if it runs as an executable, because there's no telling exactly what commands are being processed silently and without your knowledge. Virtually no legitimate coder will create an executable solely for the purpose of "hiding" what commands or strings are processed in order to prevent any potential copying of his/her actual code (i.e. keeping each process-block step private). This has never been an approved or acceptable form of executable creation and such scripts are removed from official repositories 99% of the time.

    System Component Packages should not have their visibility modified and then force-removed through the registry. This is a clumsy way of removing said packages. The proper way for Component Package removal is to change the permanency values from "permanent" to "removable", which allows for them to be removed without derping around in the registry.

    If I remember with WIM_Tweak, and someone correct me if I'm wrong, it removes ALL packages pertaining to a specific System Application and does not allow for one to select which packages to remove and which to retain. This can cause further issues particularly if you're removing a System Application with multiple component packages that interact across the system as a whole. SecHealthUI (Windows Defender) is like this.

    If you're looking for Component Package removal, I have a few PowerShell functions I could upload that you could use.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. lewcass

    lewcass MDL Senior Member

    Mar 10, 2018
    429
    251
    10
    I am still getting my head round bat files let alone powershell. CBSEnum works well on a live install. Remove-Update-Capture.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...