Windows 10: Setting DCOM authorities by script

Discus and support Setting DCOM authorities by script in Windows 10 Performance & Maintenance to solve the problem; I've been trying to set DCOM authorities via powershell (specifically for the 10016 error often reported here on Tenforums). I've no problem making... Discussion in 'Windows 10 Performance & Maintenance' started by lx07, Jan 5, 2016.

  1. lx07 Win User

    Setting DCOM authorities by script


    I've been trying to set DCOM authorities via powershell (specifically for the 10016 error often reported here on Tenforums).

    I've no problem making them look the same when looked at through both through the GUI and powershell but adding this by powershell breaks all modern apps (and *Start and so on) whereas doing the same through GUI doesn't. Code: function Add-DACL($domain, $name) { $trusteeObj = ([wmiclass]'Win32_Trustee').psbase.CreateInstance() $trusteeObj.Name = $name $trusteeObj.Domain = $domain $ace = ([wmiclass]'Win32_ACE').psbase.CreateInstance() $ace.AccessMask = 11 $ace.AceFlags = 0 $ace.AceType = 0 $ace.trustee = $trusteeObj $descL.DACL += [System.Management.ManagementBaseObject]$ace Write-Host "Set local activation DCOM authority for"$trusteeObj.Domain"/"$trusteeObj.Name }[/quote]
    When I look everything is the same - same DACL (except my change), same SACL, same control flags

    Before Code: __GENUS : 2 __CLASS : Win32_SecurityDescriptor __SUPERCLASS : __SecurityDescriptor __DYNASTY : __SecurityRelatedClass __RELPATH : __PROPERTY_COUNT : 6 __DERIVATION : {__SecurityDescriptor, __SecurityRelatedClass} __SERVER : __NAMESPACE : __PATH : ControlFlags : 32788 DACL : {} Group : System.Management.ManagementBaseObject Owner : System.Management.ManagementBaseObject SACL : {} TIME_CREATED : PSComputerName :[/quote] After Code: __GENUS : 2 __CLASS : Win32_SecurityDescriptor __SUPERCLASS : __SecurityDescriptor __DYNASTY : __SecurityRelatedClass __RELPATH : __PROPERTY_COUNT : 6 __DERIVATION : {__SecurityDescriptor, __SecurityRelatedClass} __SERVER : __NAMESPACE : __PATH : ControlFlags : 32788 DACL : {System.Management.ManagementBaseObject, System.Management.ManagementBaseObject} Group : System.Management.ManagementBaseObject Owner : System.Management.ManagementBaseObject SACL : {} TIME_CREATED : PSComputerName :[/quote]
    Is there some other security I'm not aware of? I've many times restored and made the same changes through wmi and the gui but whereas the gui works the powershell doesn't.

    Here is the whole lot btw Code: #------------------------------------------------------------------------------------------------------------------------------------------------------ # Functions #------------------------------------------------------------------------------------------------------------------------------------------------------ function enable-privilege { param( ## The privilege to adjust. This set is taken from Privilege Constants (Windows) [ValidateSet( "SeAssignPrimaryTokenPrivilege", "SeAuditPrivilege", "SeBackupPrivilege", "SeChangeNotifyPrivilege", "SeCreateGlobalPrivilege", "SeCreatePagefilePrivilege", "SeCreatePermanentPrivilege", "SeCreateSymbolicLinkPrivilege", "SeCreateTokenPrivilege", "SeDebugPrivilege", "SeEnableDelegationPrivilege", "SeImpersonatePrivilege", "SeIncreaseBasePriorityPrivilege", "SeIncreaseQuotaPrivilege", "SeIncreaseWorkingSetPrivilege", "SeLoadDriverPrivilege", "SeLockMemoryPrivilege", "SeMachineAccountPrivilege", "SeManageVolumePrivilege", "SeProfileSingleProcessPrivilege", "SeRelabelPrivilege", "SeRemoteShutdownPrivilege", "SeRestorePrivilege", "SeSecurityPrivilege", "SeShutdownPrivilege", "SeSyncAgentPrivilege", "SeSystemEnvironmentPrivilege", "SeSystemProfilePrivilege", "SeSystemtimePrivilege", "SeTakeOwnershipPrivilege", "SeTcbPrivilege", "SeTimeZonePrivilege", "SeTrustedCredManAccessPrivilege", "SeUndockPrivilege", "SeUnsolicitedInputPrivilege")] $Privilege, ## The process on which to adjust the privilege. Defaults to the current process. $ProcessId = $pid, ## Switch to disable the privilege, rather than enable it. [Switch] $Disable ) ## Taken from P/Invoke.NET with minor adjustments. $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 relen); [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 SE_PRIVILEGE_DISABLED = 0x00000000; internal const int TOKEN_QUERY = 0x00000008; internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020; public static bool EnablePrivilege(long processHandle, string privilege, bool disable) { 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; if(disable) { tp.Attr = SE_PRIVILEGE_DISABLED; } else { 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 $ProcessId).Handle $type = Add-Type $definition -PassThru $type[0]::EnablePrivilege($processHandle, $Privilege, $Disable) } #------------------------------------------------------------------------------------------------------------------------------------------------------ function Takeown-Registry($key) { switch ($key.split('\')[0]) { "HKEY_CLASSES_ROOT" { $reg = [Microsoft.Win32.Registry]::ClassesRoot $key = $key.substring(18) } "HKEY_CURRENT_USER" { $reg = [Microsoft.Win32.Registry]::CurrentUser $key = $key.substring(18) } "HKEY_LOCAL_MACHINE" { $reg = [Microsoft.Win32.Registry]::LocalMachine $key = $key.substring(19) } } # set owner $key = $reg.OpenSubKey($key, "ReadWriteSubTree", "TakeOwnership") $owner = [Security.Principal.NTAccount]"Administrators" $acl = $key.GetAccessControl() $acl.SetOwner($owner) $key.SetAccessControl($acl) # set FullControl $acl = $key.GetAccessControl() $rule = New-Object System.Security.AccessControl.RegistryAccessRule("Administrators", "FullControl", "Allow") $acl.SetAccessRule($rule) $key.SetAccessControl($acl) # reset owner $owner = [Security.Principal.NTAccount]"NT SERVICE\TrustedInstaller" $acl = $key.GetAccessControl() $acl.SetOwner($owner) $key.SetAccessControl($acl) } #------------------------------------------------------------------------------------------------------------------------------------------------------ function Add-DACL($domain, $name) { $trusteeObj = ([wmiclass]'Win32_Trustee').psbase.CreateInstance() $trusteeObj.Name = $name $trusteeObj.Domain = $domain $ace = ([wmiclass]'Win32_ACE').psbase.CreateInstance() $ace.AccessMask = 11 $ace.AceFlags = 0 $ace.AceType = 0 $ace.trustee = $trusteeObj $descL.DACL += [System.Management.ManagementBaseObject]$ace Write-Host "Set local activation DCOM authority for"$trusteeObj.Domain"/"$trusteeObj.Name } #------------------------------------------------------------------------------------------------------------------------------------------------------ # Grant authority to registry key Write-Host "Elevating priviledges for this process" -f yellow do {$result = enable-privilege SeTakeOwnershipPrivilege } until ($result -eq $true) do {$result = enable-privilege SeRestorePrivilege } until ($result -eq $true) $key="HKEY_CLASSES_ROOT\AppID\{9CA88EE3-ACB7-47c8-AFC4-AB702511C276}" Write-Host "Take ownership of $key" -f yellow Takeown-Registry($key) $key="HKEY_CLASSES_ROOT\CLSID\{D63B10C5-BB46-4990-A94F-E40B9D520160}" Write-Host "Take ownership of $key" -f yellow Takeown-Registry($key) # Get current DCOM authorities (Based on TechNet Set DCOM ACL with powerShell) $wmi = Get-WmiObject -Class Win32_DCOMApplicationSetting -Filter 'caption="RuntimeBroker"' -EnableAllPrivileges $descL = $wmi.GetLaunchSecurityDescriptor().descriptor # Reset default authorities $trusteeObj = ([wmiclass]'Win32_Trustee').psbase.CreateInstance() $trusteeObj.Name = "ALL APPLICATION PACKAGES" $trusteeObj.Domain = "APPLICATION PACKAGE AUTHORITY" $TrusteeObj.SIDString = "S-1-15-2-1" $ace = ([wmiclass]'Win32_ACE').psbase.CreateInstance() $ace.AccessMask = 11 $ace.AceFlags = 0 $ace.AceType = 0 $ace.trustee = $trusteeObj $descL.DACL = [System.Management.ManagementBaseObject]$ace Write-Host "Set local activation DCOM authority for"$trusteeObj.Domain"/"$trusteeObj.Name Add-DACL "NT AUTHORITY" "Self" # Extra authorities Add-DACL "NT AUTHORITY" "LocalService" Add-DACL "NT AUTHORITY" "System" # Update DCOM authorities $Update = $wmi.SetLaunchSecurityDescriptor($descL) if ($Update.ReturnValue) { Write-Host "Updated DCOM local activation authorities failed" -f Red } else { Write-Host "Updated DCOM local activation authorities" -f Yellow } Read-Host[/quote]

    I'd appreciate any suggestions as I'm stuck.

    Changing the registry permissions works, changing the DCOM permissions breaks everything.

    I hope I've included above everywhere I copied bits of the code from.. I'm not a programmer - I'm just trying to learn by picking a problem and trying to solve it. I think it is nearly there but there is some security in Windows I don't know about.

    Thanks for your time.

    :)
     
    lx07, Jan 5, 2016
    #1
  2. NilsRH Win User

    Event log writes error related to application-specific permissions on Windows 10 computer

    Yes.

    There is a PowerShell script (run as administrator) that makes this all very easy. I have successfully used this myself but it is always good practice to image your computer or at least make a restore point before doing this.

    Windows 10 Event ID 10010 and 10016 Errors With DistributedCOM - Page 5 - Windows 10 Forums

    At the very bottom of the script you will find the following lines. You just have to replace the two registry keys with the ones from the event log error.

    When the script successfully completes you can go into DCOM and add the permissions you want. In the run dialog type dcomcnfg then click OK.

    $key="HKEY_CLASSES_ROOT\AppID\{9CA88EE3-ACB7-47c8-AFC4-AB702511C276}"

    Write-Host "Granting authority to $key"

    Takeown-Registry($key)

    $key="HKEY_CLASSES_ROOT\CLSID\{D63B10C5-BB46-4990-A94F-E40B9D520160}"

    Write-Host "Granting authority to $key"

    Takeown-Registry($key)

    I have rid my computer of 10016 errors but it still freezes occasionally. Ninety % of the time I can unfreeze it with Ctrl alt delete and maneuvering to Task Manager with the up arrow key and hitting enter. When Task Manager opens it usually unfreezes things.
     
    NilsRH, Jan 5, 2016
    #2
  3. error: event id 10016, specifically a DCOM error

    I've created a new account and it still doesn't work. I think I just need to add NT AUTHORITY\LOCAL SERVICE SID (S-1-5-19) to the list but everything in the DCOM is just greyed out
     
    stevestockam, Jan 5, 2016
    #3
Thema:

Setting DCOM authorities by script

Loading...
  1. Setting DCOM authorities by script - Similar Threads - Setting DCOM authorities

  2. DCOM settings are not working

    in Windows 10 Gaming
    DCOM settings are not working: I am working on Windows server 2022, where I tried doing DCOM settings for OPC communication. But the OPC server isn't communicating. Kindly guide for correct DCOM setting to be done specific to Windows server 2022....
  3. DCOM settings are not working

    in Windows 10 Software and Apps
    DCOM settings are not working: I am working on Windows server 2022, where I tried doing DCOM settings for OPC communication. But the OPC server isn't communicating. Kindly guide for correct DCOM setting to be done specific to Windows server 2022....
  4. Search not functioning after changing DCOM settings

    in Windows 10 Gaming
    Search not functioning after changing DCOM settings: After changing the DCOM default Authentication Level in Component Services from 'Connect' to 'None' and restarting the device, the Search function no longer works. Typing in the search bar, pressing Win+S or typing anything with the start menu open does not give any...
  5. Search not functioning after changing DCOM settings

    in Windows 10 Software and Apps
    Search not functioning after changing DCOM settings: After changing the DCOM default Authentication Level in Component Services from 'Connect' to 'None' and restarting the device, the Search function no longer works. Typing in the search bar, pressing Win+S or typing anything with the start menu open does not give any...
  6. Search not functioning after changing DCOM settings

    in Windows 10 Customization
    Search not functioning after changing DCOM settings: After changing the DCOM default Authentication Level in Component Services from 'Connect' to 'None' and restarting the device, the Search function no longer works. Typing in the search bar, pressing Win+S or typing anything with the start menu open does not give any...
  7. DCOM settings ---COM security/Edit Limits

    in Windows 10 Software and Apps
    DCOM settings ---COM security/Edit Limits: Hi, I want to enquiry something related to DCOM settings.I want to change the settings of "COM security/Edit Limits", but the option is grayed out.Can somebody guide me how to make the 2 buttons enabled. Thanks.I have attached the windows version and the issue below....
  8. Application of settings described in KB5004442 DCOM hardening

    in Windows 10 Software and Apps
    Application of settings described in KB5004442 DCOM hardening: Hello,The updates described in KB5004442 which will be coming in June of 2022 will "force" a hardened DCOM setting for clients. Will these changes be released in the cumulative security update for the month of June or will it be a separate update? If the June update is...
  9. *%$#* DCOM

    in Windows 10 BSOD Crashes and Debugging
    *%$#* DCOM: To say that I am beyond fed up with Windows 10 is an understatement. And above that this DCOM system that you have that I constantly have to fix it is so far beyond ridiculous there is not an accurate insult or comparison of failure other than the Hindenburg that can compare...
  10. DCOM errors when attempting to run ashx scripts

    in Windows 10 BSOD Crashes and Debugging
    DCOM errors when attempting to run ashx scripts: I just got a new Surface Pro 6 and I've installed IIS, Visual Studio Code, etc., but I can't get ashx scripts to run on this PC. Even the simplest ashx script fails to run. The same scripts run on other Windows 10 machines. I've set the same options in IIS. I am getting...