HotCakeX / Harden-Windows-Security

Harden Windows Safely, Securely using Official Supported Microsoft methods and proper explanation | Always up-to-date and works with the latest build of Windows | Provides tools and Guides for Personal, Enterprise, Government and Military security levels | Read The Rationale https://github.com/HotCakeX/Harden-Windows-Security/blob/main/Rationale.md
https://hotcakex.github.io
MIT License
1.84k stars 143 forks source link

[Bug]: The GUI freezes when working with ASR rules or country IP blocking. #350

Closed agpt8 closed 1 month ago

agpt8 commented 1 month ago

Tools category

Harden Windows Security Module

Does Your System Meet The Requirements?

Is your Windows Installation Genuine?

Did You Read The Frequently Asked Questions?

Please Explain The Bug

This issue was initially discussed in discussion #349. This is the tracking issue for it and all communications going forward regarding this will be held here.

@agpt8: While configuring ASR rules in the GUI, there seems to be a bug. When attempting to change the setting to 'Audit' for the preview rules, which often cause issues (particularly when updating Nvidia drivers), selecting the appropriate rule from the dropdown and clicking the play button results does something in the background, but the GUI displays an error message with links to GitHub. After clicking 'okay', the GUI freezes and exits to the terminal PS process without closing the GUI window itself, displaying the trace there. The ASR rule setting does not change during all this and must be modified from GPO manually.

Frozen window while executing ASR rule changes: image

@HotCakeX : It's related to displaying notifications at the end, so it does its job but when at the end it should show the notification it throws error. I couldn't reproduce it but do you see this for any other action too? like when checking for compliance or applying protection, do you see notification properly? You might not see notification at all if there are conflicting modules that use the same dlls and the module should gracefully back off when that happens.

@agpt8: I dont see any other notifications when compliance checking or using specific protection from the protect tab, maybe because of the modules that I am using. These execute just fine and I havent had any issues. However, with the ASR rules, I saw this issue.

Okay I was trying to reproduce above issue with ASR rules. but I again hit this issue this time with protect tab itself. Again the window froze including the window controls. I had to use End task button from the taskbar to close it. The trace is similar to what I posted above. Here is a video.

https://1drv.ms/v/s!AkRt3_pvmCxG4pkhz0NQX2g7N1Rx0w?e=qNyC8y

This second video is taken after removing all PS modules that were loaded by removing everything in the $PROFILE file. I did not remove/turn off anything that was loaded from powertoys, since it hasnt really caused any issues before and I used it this morning to apply the updated protections and it worked fine. While the compliance check worked fine and I got the notifications as well (this did not happen when my modules were loaded but the compliance check would still work). However, the Protect tab gave me an error as seen on the video. I could not capture trace this time. I'll update this comment after capturing extended trace using Get-Error. I'll also post the link once it is uploaded on onedrive.

Update 1: video link: https://1drv.ms/v/s!AkRt3_pvmCxG4pkkeR3FZW7Iu8qwQA?e=zl7nd7

@HotCakeX: That's a weird error, it happens randomly when the existing country IP blocking rules are being deleted in order to add new rules. Sometimes this deletion throws an error about access denied, sometimes it doesn't, i can't consistently repro it, making it very hard to solve. Out of over 30 times i tried it, i only got the error about 3 times.

Access denied errors usually mean there are not enough privileges, but we are running as Admin already and that should be enough for that task. I don't think it's too far fetched to attribute this problem to 24H2, I haven't changed this part of the code in a while and it always used to work.

This is the exact line that intermittently throws that access denied error, in case anyone wants to take a look

Harden-Windows-Security/Harden-Windows-Security Module/Main files/C#/CimInstances/FirewallHelper.cs

@agpt8: Could this be related to the new enhanced admin protection setting that was added in windows? I have that enabled. That is the only setting that changes how the privileges are granted.

@HotCakeX: Could be (easy to test the theory) but then again why is it so random! 🤷‍♀️

Error Details

PS C:\Users\ayush> Protect-WindowsSecurity -GUI
MethodInvocationException: Exception calling "Run" with "1" argument(s): "Access is denied. "

ErrorRecord                 : Exception calling "Run" with "1" argument(s): "Access is denied. "
WasThrownFromThrowStatement : False
TargetSite                  : Void CheckActionPreference(System.Management.Automation.Language.FunctionContext,
                              System.Exception)
Message                     : Exception calling "Run" with "1" argument(s): "Access is denied. "
Data                        : {[System.Management.Automation.Interpreter.InterpretedFrameInfo,
                              System.Management.Automation.Interpreter.InterpretedFrameInfo[]]}
InnerException              : Microsoft.Management.Infrastructure.CimException: Access is denied.
                                 at Microsoft.Management.Infrastructure.Internal.Operations.CimSyncEnumeratorBase`1.Mov
                              eNext()
                                 at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found)
                                 at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
                                 at HardenWindowsSecurity.FirewallHelper.<BlockIPAddressListsInGroupPolicy>g__CreateFir
                              ewallRule|14_2(CimSession cimSession, String name, String[] ipList, Boolean isInbound)
                                 at HardenWindowsSecurity.FirewallHelper.BlockIPAddressListsInGroupPolicy(String
                              DisplayName, String ListDownloadURL, Boolean ToAdd)
                                 at HardenWindowsSecurity.CountryIPBlocking.Invoke()
                                 at HardenWindowsSecurity.GUIProtectWinSecurity.<>c.<AddEventHandlers>b__0_18()
                                 at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread
                              threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object
                              state)
                              --- End of stack trace from previous location ---
                                 at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread
                              threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object
                              state)
                                 at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread
                              threadPoolThread)
                              --- End of stack trace from previous location ---
                                 at
                              HardenWindowsSecurity.GUIProtectWinSecurity.<>c.<<AddEventHandlers>b__0_10>d.MoveNext()
                              --- End of stack trace from previous location ---
                                 at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
                                 at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback,
                              Object args, Int32 numArgs)
                                 at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate
                              callback, Object args, Int32 numArgs, Delegate catchHandler)
                                 at System.Windows.Threading.DispatcherOperation.InvokeImpl()
                                 at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
                                 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,
                              ContextCallback callback, Object state)
                              --- End of stack trace from previous location ---
                                 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,
                              ContextCallback callback, Object state)
                                 at
                              MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext
                              executionContext, ContextCallback callback, Object state)
                                 at System.Windows.Threading.DispatcherOperation.Invoke()
                                 at System.Windows.Threading.Dispatcher.ProcessQueue()
                                 at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr
                              wParam, IntPtr lParam, Boolean& handled)
                                 at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
                                 at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback,
                              Object args, Int32 numArgs)
                                 at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate
                              callback, Object args, Int32 numArgs, Delegate catchHandler)
                                 at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority,
                              TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
                                 at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam,
                              IntPtr lParam)
                                 at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
                                 at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
                                 at System.Windows.Application.RunDispatcher(Object ignore)
                                 at System.Windows.Application.RunInternal(Window window)
                                 at CallSite.Target(Closure, CallSite, Application, Window)
HelpLink                    :
Source                      : System.Management.Automation
HResult                     : -2146233087
StackTrace                  :    at
                              System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext
                              funcContext, Exception exception)
                                 at
                              System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame
                              frame)
                                 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(Interp
                              retedFrame frame)
                                 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(Interp
                              retedFrame frame)

MyCommand             :
BoundParameters       : {}
UnboundArguments      : {}
ScriptLineNumber      : 352
OffsetInLine          : 17
HistoryId             : 2
ScriptName            : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.5\Core\
                        Protect-WindowsSecurity.psm1
Line                  :                 [System.Void]
                        [HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)

Statement             : [System.Void]
                        [HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)
PositionMessage       : At C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.5\Co
                        re\Protect-WindowsSecurity.psm1:352 char:17
                        + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
                        +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot          : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.5\Core
PSCommandPath         : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.5\Core\
                        Protect-WindowsSecurity.psm1
InvocationName        :
PipelineLength        : 0
PipelinePosition      : 0
ExpectingInput        : False
CommandOrigin         : Internal
DisplayScriptPosition :

PS C:\Users\ayush> Get-Error

Exception             :
    Type           : System.Management.Automation.MethodInvocationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Exception calling "Run" with "1" argument(s): "Access is denied. "
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : CimException
        InvocationInfo        :
            ScriptLineNumber : 352
            OffsetInLine     : 17
            HistoryId        : 2
            ScriptName       : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.
5\Core\Protect-WindowsSecurity.psm1
            Line             : [System.Void]
[HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)

            Statement        : [System.Void]
[HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)
            PositionMessage  : At C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0
.6.5\Core\Protect-WindowsSecurity.psm1:352 char:17
                               + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
                               +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            PSScriptRoot     :
C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.5\Core
            PSCommandPath    : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.
5\Core\Protect-WindowsSecurity.psm1
            CommandOrigin    : Internal
        ScriptStackTrace      : at Protect-WindowsSecurity<Begin>, C:\Users\ayush\OneDrive\Documents\PowerShell\Modules
\Harden-Windows-Security-Module\0.6.5\Core\Protect-WindowsSecurity.psm1: line 352
                                at <ScriptBlock>, <No file>: line 1
    TargetSite     :
        Name          : CheckActionPreference
        DeclaringType : [System.Management.Automation.ExceptionHandlingOps]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message        : Exception calling "Run" with "1" argument(s): "Access is denied. "
    Data           : System.Collections.ListDictionaryInternal
    InnerException :
        Type            : Microsoft.Management.Infrastructure.CimException
        NativeErrorCode : AccessDenied
        ErrorData       : MSFT_WmiError
        MessageId       : Windows System Error 5
        StatusCode      : 2
        TargetSite      :
            Name          : MoveNext
            DeclaringType : [Microsoft.Management.Infrastructure.Internal.Operations.CimSyncEnumeratorBase`1[T]]
            MemberType    : Method
            Module        : Microsoft.Management.Infrastructure.dll
        Message         : Access is denied.
        Data            : System.Collections.ListDictionaryInternal
        Source          : Microsoft.Management.Infrastructure
        HResult         : -2146233088
        StackTrace      :
   at Microsoft.Management.Infrastructure.Internal.Operations.CimSyncEnumeratorBase`1.MoveNext()
   at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at HardenWindowsSecurity.FirewallHelper.<BlockIPAddressListsInGroupPolicy>g__CreateFirewallRule|14_2(CimSession
cimSession, String name, String[] ipList, Boolean isInbound)
   at HardenWindowsSecurity.FirewallHelper.BlockIPAddressListsInGroupPolicy(String DisplayName, String
ListDownloadURL, Boolean ToAdd)
   at HardenWindowsSecurity.CountryIPBlocking.Invoke()
   at HardenWindowsSecurity.GUIProtectWinSecurity.<>c.<AddEventHandlers>b__0_18()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext
executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext
executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at HardenWindowsSecurity.GUIProtectWinSecurity.<>c.<<AddEventHandlers>b__0_10>d.MoveNext()
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32
numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback,
Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback,
Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext,
ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&
handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32
numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate
method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at CallSite.Target(Closure, CallSite, Application, Window)
    Source         : System.Management.Automation
    HResult        : -2146233087
    StackTrace     :
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception
exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : CimException
InvocationInfo        :
    ScriptLineNumber : 352
    OffsetInLine     : 17
    HistoryId        : 2
    ScriptName       : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.5\Core\P
rotect-WindowsSecurity.psm1
    Line             : [System.Void]
[HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)

    Statement        : [System.Void]
[HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)
    PositionMessage  : At C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.5\Cor
e\Protect-WindowsSecurity.psm1:352 char:17
                       + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
                       +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.5\Core
    PSCommandPath    : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.5\Core\P
rotect-WindowsSecurity.psm1
    CommandOrigin    : Internal
ScriptStackTrace      : at Protect-WindowsSecurity<Begin>, C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-
Windows-Security-Module\0.6.5\Core\Protect-WindowsSecurity.psm1: line 352
                        at <ScriptBlock>, <No file>: line 1

PS C:\Users\ayush> Get-Module

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     0.6.5                 Harden-Windows-Security-Module      {Confirm-SystemCompliance, Protect-WindowsSecurit…
Manifest   7.0.0.0               Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-It…
Manifest   7.0.0.0               Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString…
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Ob…
Script     2.3.5                 PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, …
HotCakeX commented 1 month ago

So this trace is different than the one in the discussion post that you first showed me, but that's okay. This one is about the strange access denied error that would happened randomly, can't do anything about it but i also can't reproduce it anymore either. Since then build 26100.2033 of 24H2 was released, fixed a couple of issues, maybe it was fixed by it.

For notifications, i installed PowerToys, set up the command not found feature, and when i run the module, i don't see notifications, which is expected since it allows other competing modules to load their dlls in the session.

I couldn't reproduce the issue you showed me here, although i did make the notification showing method more resilient just in case. That trace appears to be unrelated to the module. After having a closer look, it's referring to the Microsoft.Windows.SDK.NET dll with version 10.0.26100.38 but since version 0.6.5, the module uses dll's latest version which is 10.0.26100.46.

I reviewed any related code but they all seemed fine and work fine, with this pull request for version 0.6.6 i'm gonna mark this as closed. You can try version 0.6.6 to see if you continue seeing that error, i think if you install the latest cumulative update and version 0.6.6 it's gonna be okay.

agpt8 commented 1 month ago

I still got the freeze. This time the workflow was to open the GUI, choose TLS, networking and IP blocking rules along with the optional ones they present and execute. This executed just fine, so I wanted to check the result in the Confirm tab. I press the play button at the bottom which is when I hit the error again.

Here is the trace:

ayush in ~
❯ Protect-WindowsSecurity -GUI
MethodInvocationException: Exception calling "Run" with "1" argument(s): "Timeout exceeded while waiting for the MDM policy files to be created."

ErrorRecord                 : Exception calling "Run" with "1" argument(s): "Timeout exceeded while waiting for the
                              MDM policy files to be created."
WasThrownFromThrowStatement : False
TargetSite                  : Void CheckActionPreference(System.Management.Automation.Language.FunctionContext,
                              System.Exception)
Message                     : Exception calling "Run" with "1" argument(s): "Timeout exceeded while waiting for the
                              MDM policy files to be created."
Data                        : {[System.Management.Automation.Interpreter.InterpretedFrameInfo,
                              System.Management.Automation.Interpreter.InterpretedFrameInfo[]]}
InnerException              : System.TimeoutException: Timeout exceeded while waiting for the MDM policy files to be
                              created.
                                 at HardenWindowsSecurity.InvokeConfirmation.Invoke(String[] Categories)
                                 at HardenWindowsSecurity.GUIMain.NavigationVM.<>c__DisplayClass4_0.<Confirm>b__10()
                                 at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread
                              threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object
                              state)
                              --- End of stack trace from previous location ---
                                 at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread
                              threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object
                              state)
                                 at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread
                              threadPoolThread)
                              --- End of stack trace from previous location ---
                                 at HardenWindowsSecurity.GUIMain.NavigationVM.<>c__DisplayClass4_0.<<Confirm>b__7>d.Mo
                              veNext()
                              --- End of stack trace from previous location ---
                                 at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
                                 at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback,
                              Object args, Int32 numArgs)
                                 at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate
                              callback, Object args, Int32 numArgs, Delegate catchHandler)
                                 at System.Windows.Threading.DispatcherOperation.InvokeImpl()
                                 at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
                                 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,
                              ContextCallback callback, Object state)
                              --- End of stack trace from previous location ---
                                 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,
                              ContextCallback callback, Object state)
                                 at
                              MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext
                              executionContext, ContextCallback callback, Object state)
                                 at System.Windows.Threading.DispatcherOperation.Invoke()
                                 at System.Windows.Threading.Dispatcher.ProcessQueue()
                                 at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr
                              wParam, IntPtr lParam, Boolean& handled)
                                 at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam,
                              Boolean& handled)
                                 at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback,
                              Object args, Int32 numArgs)
                                 at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate
                              callback, Object args, Int32 numArgs, Delegate catchHandler)
                                 at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority,
                              TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
                                 at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam,
                              IntPtr lParam)
                                 at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
                                 at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
                                 at System.Windows.Application.RunDispatcher(Object ignore)
                                 at System.Windows.Application.RunInternal(Window window)
                                 at CallSite.Target(Closure, CallSite, Application, Window)
HelpLink                    :
Source                      : System.Management.Automation
HResult                     : -2146233087
StackTrace                  :    at
                              System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext
                              funcContext, Exception exception)
                                 at
                              System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame
                              frame)
                                 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(Interp
                              retedFrame frame)
                                 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(Interp
                              retedFrame frame)

MyCommand             :
BoundParameters       : {}
UnboundArguments      : {}
ScriptLineNumber      : 364
OffsetInLine          : 17
HistoryId             : 1
ScriptName            : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.6\Core\
                        Protect-WindowsSecurity.psm1
Line                  :                 [System.Void]
                        [HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)

Statement             : [System.Void]
                        [HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)
PositionMessage       : At C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.6\Co
                        re\Protect-WindowsSecurity.psm1:364 char:17
                        + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
                        +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot          : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.6\Core
PSCommandPath         : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.6\Core\
                        Protect-WindowsSecurity.psm1
InvocationName        :
PipelineLength        : 0
PipelinePosition      : 0
ExpectingInput        : False
CommandOrigin         : Internal
DisplayScriptPosition :

ayush in ~
❯ Get-Error

Exception             :
    Type           : System.Management.Automation.MethodInvocationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Exception calling "Run" with "1" argument(s): "Timeout exceeded while waiting for the MDM policy
files to be created."
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : TimeoutException
        InvocationInfo        :
            ScriptLineNumber : 364
            OffsetInLine     : 17
            HistoryId        : 1
            ScriptName       : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.
6\Core\Protect-WindowsSecurity.psm1
            Line             : [System.Void]
[HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)

            Statement        : [System.Void]
[HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)
            PositionMessage  : At C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0
.6.6\Core\Protect-WindowsSecurity.psm1:364 char:17
                               + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
                               +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            PSScriptRoot     :
C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.6\Core
            PSCommandPath    : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.
6\Core\Protect-WindowsSecurity.psm1
            CommandOrigin    : Internal
        ScriptStackTrace      : at Protect-WindowsSecurity<Begin>, C:\Users\ayush\OneDrive\Documents\PowerShell\Modules
\Harden-Windows-Security-Module\0.6.6\Core\Protect-WindowsSecurity.psm1: line 364
                                at <ScriptBlock>, <No file>: line 1
    TargetSite     :
        Name          : CheckActionPreference
        DeclaringType : [System.Management.Automation.ExceptionHandlingOps]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message        : Exception calling "Run" with "1" argument(s): "Timeout exceeded while waiting for the MDM policy
files to be created."
    Data           : System.Collections.ListDictionaryInternal
    InnerException :
        Type       : System.TimeoutException
        TargetSite :
            Name          : Invoke
            DeclaringType : [HardenWindowsSecurity.InvokeConfirmation]
            MemberType    : Method
            Module        : h2jexxty.4ef.dll
        Message    : Timeout exceeded while waiting for the MDM policy files to be created.
        Data       : System.Collections.ListDictionaryInternal
        Source     : h2jexxty.4ef
        HResult    : -2146233083
        StackTrace :
   at HardenWindowsSecurity.InvokeConfirmation.Invoke(String[] Categories)
   at HardenWindowsSecurity.GUIMain.NavigationVM.<>c__DisplayClass4_0.<Confirm>b__10()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext
executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext
executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at HardenWindowsSecurity.GUIMain.NavigationVM.<>c__DisplayClass4_0.<<Confirm>b__7>d.MoveNext()
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32
numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback,
Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback,
Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext,
ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&
handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32
numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate
method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at CallSite.Target(Closure, CallSite, Application, Window)
    Source         : System.Management.Automation
    HResult        : -2146233087
    StackTrace     :
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception
exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : TimeoutException
InvocationInfo        :
    ScriptLineNumber : 364
    OffsetInLine     : 17
    HistoryId        : 1
    ScriptName       : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.6\Core\P
rotect-WindowsSecurity.psm1
    Line             : [System.Void]
[HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)

    Statement        : [System.Void]
[HardenWindowsSecurity.GUIMain]::app.Run([HardenWindowsSecurity.GUIMain]::mainGUIWindow)
    PositionMessage  : At C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.6\Cor
e\Protect-WindowsSecurity.psm1:364 char:17
                       + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
                       +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.6\Core
    PSCommandPath    : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.6\Core\P
rotect-WindowsSecurity.psm1
    CommandOrigin    : Internal
ScriptStackTrace      : at Protect-WindowsSecurity<Begin>, C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-
Windows-Security-Module\0.6.6\Core\Protect-WindowsSecurity.psm1: line 364
                        at <ScriptBlock>, <No file>: line 1

I dont know if this is relevant here but I havent installed the latest RP build 26100.2033 on my machine as it is erroring out. I have tried the traditional update through settings, wusa.exe, Dism and Add-Package. The update files were obtained from the official update catalog. Add-Package would error out on both the files. wusa and double clicking the files itself work the same and only one of them installed. For Dism, one of the packages installed just fine, other one gave an error saying registry file format is incorrect. Not sure what the reason here is but still trying to find a workaround.

HotCakeX commented 1 month ago

@agpt8 It's saying the MDM related data couldn't be collected within the designated time frame. Can't do anything about it since it's not a bug. My system couldn't be updated to 26100.2033 through Windows Update either so i just downloaded the files and installed them in order.

https://www.catalog.update.microsoft.com/Search.aspx?q=KB5044284

and the order of installation is defined here

https://support.microsoft.com/en-us/topic/october-8-2024-kb5044284-os-build-26100-2033-6baf4a06-9763-4d9b-ba8a-f25ba6ed477b#ID0ELBD=Catalog

image

agpt8 commented 1 month ago

Yeah. The first package installed just fine with dism, 2nd one just does not want to install.

HotCakeX commented 1 month ago

Yeah. The first package installed just fine with dism, 2nd one just does not want to install.

Maybe try a reset from the settings. Btw my PC had this problem with update installation on 24H2 before i started applying any policies or using the Harden Windows Security module. I did report it on feedback hub.

I was watching the update process closely in event viewer, the ASR rules, code integrity logs etc. no related logs were generated either.