Removing Hidden Components In Windows 10 Using Powershell
please help!
i searching internet forever script in powershell 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 making components visible second taking ownership of registry.
eventualy after lot of searching found script thx peter hinchley online.
i wondering if possible script offline using dism.exe /mount-wim /wimfile:c:\"pathtowim"\install.wim /index:1 /mountdir:c:\"pathtomountwim"\"pathtowimoffline"
here's code:
function enable-privilege { param($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; tp.attr = se_privilege_enabled; retval = lookupprivilegevalue(null, privilege, ref tp.luid); retval = adjusttokenprivileges(htok, false, ref tp, 0, intptr.zero, 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.setowner($owner) $key.setaccesscontrol($acl) $acl = $key.getaccesscontrol() $rule = new-object system.security.accesscontrol.registryaccessrule "administrators", "fullcontrol", "containerinherit", "none", "allow" $acl.setaccessrule($rule) $key.setaccesscontrol($acl) } {} 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 want run script batch file (the batch file must same name script work).
powershell.exe -noprofile -command "& {start-process powershell.exe -argumentlist '-noprofile -executionpolicy bypass -file ""%~dpn0.ps1""' -verb runas}"
when searching net noticed several programmer's topic taboo,and not been discussed.
i have been using install_wim_tweak.exe , wintoolkit component removal have been nice if somebody
could write powershell script offline using dism :) appreciate it.
i hope respond thx.
hi,
thanks post, mike indicated forum can troubleshooting specific script problem, pre-written scripts, can check technet gallery.
https://gallery.technet.microsoft.com/
best regards,
please remember mark replies answers if , unmark them if provide no help. if have feedback technet subscriber support, contact tnmff@microsoft.com.
Windows Server > Windows PowerShell
Comments
Post a Comment