Removing hdden components in Windows 10

This topic contains 1 reply, has 2 voices, and was last updated by  Michael Maher 2 years, 3 months ago.

  • Author
  • #36706

    Wijz3r .

    Please Help!

    I am searching the internet forever for a script in Powershell for removing hidden components in windows 10 Using DISM.EXE (Example Microsoft-Windows-ContactSupport-Package~31bf3856ad364e35~amd64~en-US~10.0.10240.16384).

    The first problem was making the components visible second taking ownership of the registry.

    Eventualy after a lot of searching i found a script thx to Peter Hinchley but its online.

    I was wondering if its possible for this script to do it offline using Dism.exe /Mount-Wim /WimFile:C:\"PATHTOWIM"\install.wim /Index:1 /MountDir:C:\"PATHTOMOUNTWIM"\"PATHTOWIMOFFLINE"

    here's the code:

    function Enable-Privilege {
    $Definition = @'
    using System;
    using System.Runtime.InteropServices;
    public class AdjPriv {
    [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
    internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
    ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr rele);
    [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
    internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
    [DllImport("advapi32.dll", SetLastError = true)]
    internal static extern bool LookupPrivilegeValue(string host, string name,
    ref long pluid);
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    internal struct TokPriv1Luid {
    public int Count;
    public long Luid;
    public int Attr;
    internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
    internal const int TOKEN_QUERY = 0x00000008;
    internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
    public static bool EnablePrivilege(long processHandle, string privilege) {
    bool retVal;
    TokPriv1Luid tp;
    IntPtr hproc = new IntPtr(processHandle);
    IntPtr htok = IntPtr.Zero;
    retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
    ref htok);
    tp.Count = 1;
    tp.Luid = 0;
    retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
    retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero,
    return retVal;
    $ProcessHandle = (Get-Process -id $pid).Handle
    $type = Add-Type $definition -PassThru
    $type[0]::EnablePrivilege($processHandle, $Privilege)

    function Take-Over($path) {
    $owner = [Security.Principal.NTAccount]'Administrators'

    $key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($path, 'ReadWriteSubTree', 'TakeOwnership')
    $acl = $key.GetAccessControl()

    $acl = $key.getaccesscontrol()
    $rule = New-Object System.Security.AccessControl.RegistryAccessRule "Administrators", "FullControl", "ContainerInherit", "None", "Allow"

    do {} until (Enable-Privilege SeTakeOwnershipPrivilege)

    function Remove-Package($name) {
    $key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\$name"
    Take-Over $key
    Remove-Item -Path HKLM:"$key\Owners" -Force -Recurse
    & C:\Windows\System32\PkgMgr.exe /up:$name /norestart /quiet

    # Remove Contact Support.
    Remove-Package "Microsoft-Windows-ContactSupport-Package~31bf3856ad364e35~amd64~en-US~10.0.10240.16384"
    Remove-Package "Microsoft-Windows-ContactSupport-Package~31bf3856ad364e35~amd64~~10.0.10240.16384"

    # Remove Windows Feedback.
    Remove-Package "Microsoft-WindowsFeedback-Package~31bf3856ad364e35~amd64~en-US~10.0.10240.16384"
    Remove-Package "Microsoft-WindowsFeedback-Package~31bf3856ad364e35~amd64~~10.0.10240.16384"

    If you want it to run the script from a batch file (The Batch file must be the same name as the script to work).

    PowerShell.exe -NoProfile -Command ""

    When i was searching the net i noticed that several programmer's say that this topic was taboo,and not been discussed.

    I have been using install_wim_tweak.exe and Wintoolkit for component removal but it would have been nice if somebody

    could write a powershell script for this offline using dism 🙂 i would appreciate it.

    I hope someone would respond thx.

  • #36712

    Michael Maher

    Hi Wijz3r,

    Personally, I wouldn't use PowerShell for this.

    DISM has it's own cmdlet style parameters.

    Here's a series of DISM commands I ran when updating my Windows 8.1 image offlline.

    C:\Windows\system32\cmd.exe /k "C:\Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat "
    Dism /Mount-Image /ImageFile:"f:\software3\Windows 8.1 Ent x64\sources\install.wim" /Name:"Windows 8.1 Enterprise" /MountDir:F:\DISM\Offline
    DISM /Image:F:\DISM\Offline /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:"G:\Sources\sxs"
    Dism /Image:F:\DISM\Offline /get-packages >c:\temp\packages.txt
    Dism /image:F:\DISM\Offline /remove-package /packagename:Package_for_KB2966826~31bf3856ad364e35~amd64~~
    Dism /image:F:\DISM\Offline /remove-package /packagename:Package_for_KB2966828~31bf3856ad364e35~amd64~~
    Dism /Unmount-Image /MountDir:F:\DISM\Offline /Commit
    Dism /Unmount-Image /MountDir:F:\DISM\Offline /Discard


You must be logged in to reply to this topic.