Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Clicking on AppControl Manager tab crashes the GUI #513

Closed
3 tasks done
agpt8 opened this issue Jan 7, 2025 · 8 comments · Fixed by #514
Closed
3 tasks done

[Bug]: Clicking on AppControl Manager tab crashes the GUI #513

agpt8 opened this issue Jan 7, 2025 · 8 comments · Fixed by #514
Assignees
Labels
Bug 🐛 Something isn't working

Comments

@agpt8
Copy link
Contributor

agpt8 commented Jan 7, 2025

Tools category

Harden Windows Security Module

Does Your System Meet The Requirements?

  • Yes, I acknowledge that I've read the requirements and my system meets them. 👍

Is your Windows Installation Genuine?

  • Yes, I acknowledge that the installation media of the Windows OS I used the tool on was downloaded from the official Microsoft website and I didn't tamper or modify it. 💯

Did You Read The Frequently Asked Questions?

  • Yes, I've referred to the FAQs and my issue is not covered/explained in there.

Please Explain The Bug

Clicking on the AppControl Manager tab crashes the GUI. Error and stack trace below

Protect-WindowsSecurity -GUI
MethodInvocationException: Exception calling "Run" with "1" argument(s): "The type initializer for 'HardenWindowsSecurity.GUIAppControlManager'
threw an exception."


ErrorRecord                 : Exception calling "Run" with "1" argument(s): "The type initializer for
                              'HardenWindowsSecurity.GUIAppControlManager' threw an exception."
WasThrownFromThrowStatement : False
TargetSite                  : Void CheckActionPreference(System.Management.Automation.Language.FunctionContext,
                              System.Exception)
Message                     : Exception calling "Run" with "1" argument(s): "The type initializer for
                              'HardenWindowsSecurity.GUIAppControlManager' threw an exception."
Data                        : {[System.Management.Automation.Interpreter.InterpretedFrameInfo,
                              System.Management.Automation.Interpreter.InterpretedFrameInfo[]]}
InnerException              : System.TypeInitializationException: The type initializer for
                              'HardenWindowsSecurity.GUIAppControlManager' threw an exception.
                               ---> System.TypeLoadException: Method 'GetVirtualMethodTableInfoForKey' in type
                              'Windows.Management.Deployment.PackageManager' from assembly 'Microsoft.Windows.SDK.NET,
                              Version=10.0.26100.38, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have
                              an implementation.
                                 at HardenWindowsSecurity.GUIAppControlManager..cctor()
                                 --- End of inner exception stack trace ---
                                 at HardenWindowsSecurity.GUIMain.NavigationVM.AppControlManagerView(Object obj)
                                 at HardenWindowsSecurity.GUIMain.RelayCommand.Execute(Object parameter)
                                 at
                              System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
                                 at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
                                 at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args,
                              Boolean reRaised)
                                 at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs
                              args, RoutedEvent newEvent)
                                 at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
                                 at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args,
                              Boolean reRaised)
                                 at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs
                              args)
                                 at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
                                 at System.Windows.Input.InputManager.ProcessStagingArea()
                                 at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
                                 at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode
                              mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
                                 at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd,
                              WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
                                 at System.Windows.Interop.HwndSource.InputFilterMessage(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 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      : 325
OffsetInLine          : 17
HistoryId             : 1
ScriptName            : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.7.2\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.7.2\Co
                        re\Protect-WindowsSecurity.psm1:325 char:17
                        + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot          : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.7.2\Core
PSCommandPath         : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.7.2\Core\
                        Protect-WindowsSecurity.psm1
InvocationName        :
PipelineLength        : 0
PipelinePosition      : 0
ExpectingInput        : False
CommandOrigin         : Internal
DisplayScriptPosition :

Error Details

Get-Error

Exception             :
    Type           : System.Management.Automation.MethodInvocationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Exception calling "Run" with "1" argument(s): "The type initializer for
'HardenWindowsSecurity.GUIAppControlManager' threw an exception."
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : TypeInitializationException
        InvocationInfo        :
            ScriptLineNumber : 325
            OffsetInLine     : 17
            HistoryId        : 1
            ScriptName       : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.7.
2\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
.7.2\Core\Protect-WindowsSecurity.psm1:325 char:17
                               + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
                               +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            PSScriptRoot     :
C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.7.2\Core
            PSCommandPath    : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.7.
2\Core\Protect-WindowsSecurity.psm1
            CommandOrigin    : Internal
        ScriptStackTrace      : at Protect-WindowsSecurity<Begin>, C:\Users\ayush\OneDrive\Documents\PowerShell\Modules
\Harden-Windows-Security-Module\0.7.2\Core\Protect-WindowsSecurity.psm1: line 325
                                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): "The type initializer for
'HardenWindowsSecurity.GUIAppControlManager' threw an exception."
    Data           : System.Collections.ListDictionaryInternal
    InnerException :
        Type           : System.TypeInitializationException
        TypeName       : HardenWindowsSecurity.GUIAppControlManager
        TargetSite     :
            Name          : AppControlManagerView
            DeclaringType : [HardenWindowsSecurity.GUIMain+NavigationVM]
            MemberType    : Method
            Module        : hw13omc5.kwm.dll
        Message        : The type initializer for 'HardenWindowsSecurity.GUIAppControlManager' threw an exception.
        Data           : System.Collections.ListDictionaryInternal
        InnerException :
            Type       : System.TypeLoadException
            Message    : Method 'GetVirtualMethodTableInfoForKey' in type
'Windows.Management.Deployment.PackageManager' from assembly 'Microsoft.Windows.SDK.NET, Version=10.0.26100.38,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
            TypeName   : Windows.Management.Deployment.PackageManager
            TargetSite : Void .cctor()
            Source     : hw13omc5.kwm
            HResult    : -2146233054
            StackTrace :
   at HardenWindowsSecurity.GUIAppControlManager..cctor()
        Source         : hw13omc5.kwm
        HResult        : -2146233036
        StackTrace     :
   at HardenWindowsSecurity.GUIMain.NavigationVM.AppControlManagerView(Object obj)
   at HardenWindowsSecurity.GUIMain.RelayCommand.Execute(Object parameter)
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp,
RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam,
IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(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 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 : TypeInitializationException
InvocationInfo        :
    ScriptLineNumber : 325
    OffsetInLine     : 17
    HistoryId        : 1
    ScriptName       : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.7.2\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.7.2\Cor
e\Protect-WindowsSecurity.psm1:325 char:17
                       + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
                       +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.7.2\Core
    PSCommandPath    : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.7.2\Core\P
rotect-WindowsSecurity.psm1
    CommandOrigin    : Internal
ScriptStackTrace      : at Protect-WindowsSecurity<Begin>, C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-
Windows-Security-Module\0.7.2\Core\Protect-WindowsSecurity.psm1: line 325
                        at <ScriptBlock>, <No file>: line 1
@agpt8 agpt8 added the Bug 🐛 Something isn't working label Jan 7, 2025
@HotCakeX
Copy link
Owner

HotCakeX commented Jan 7, 2025

I think the reason you're seeing this is that if i remember correctly, you had other modules loading their own dlls and that would prevent this module from loading its own dlls, can you start a PowerShell with no profile switch to stop them and try again? That's the only thing i can think of that is causing this issue for you but not for me.

@HotCakeX
Copy link
Owner

HotCakeX commented Jan 7, 2025

Something is loading assembly Microsoft.Windows.SDK.NET, Version=10.0.26100.38 in your environment, the module has its own up to date dll version 10.0.26100.52, so i'm pretty sure that's the reason.

@agpt8
Copy link
Contributor Author

agpt8 commented Jan 7, 2025

I dont have .net 10 sdk or beta powershell installed.
I tried with the blank powershell profile and it worked fine. I guess it was because of something within that profile. For reference, this is in my powershell profile file:

oh-my-posh init pwsh --config 'C:\Users\ayush\AppData\Local\Programs\oh-my-posh\themes\spaceship.omp.json' | Invoke-Expression
# & ([ScriptBlock]::Create((oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\spaceship.omp.json" --print) -join "`n"))


# uv completions
(& uv generate-shell-completion powershell) | Out-String | Invoke-Expression
(& uvx --generate-shell-completion powershell) | Out-String | Invoke-Expression

# github cli shell completions
gh completion -s powershell | Out-String | Invoke-Expression

# op completion powershell | Out-String | Invoke-Expression

# rustup completions powershell | Out-String | Invoke-Expression

Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
#f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module

Import-Module -Name Microsoft.WinGet.CommandNotFound
#f45873b3-b655-43a6-b217-97c00aa0db58

# winget completions
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
    param($wordToComplete, $commandAst, $cursorPosition)
        [Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
        $Local:word = $wordToComplete.Replace('"', '""')
        $Local:ast = $commandAst.ToString().Replace('"', '""')
        winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
        }
}

# azd completion
azd completion powershell | Out-String | Invoke-Expression

# AzureCLI completions
Register-ArgumentCompleter -Native -CommandName az -ScriptBlock {
    param($commandName, $wordToComplete, $cursorPosition)
    $completion_file = New-TemporaryFile
    $env:ARGCOMPLETE_USE_TEMPFILES = 1
    $env:_ARGCOMPLETE_STDOUT_FILENAME = $completion_file
    $env:COMP_LINE = $wordToComplete
    $env:COMP_POINT = $cursorPosition
    $env:_ARGCOMPLETE = 1
    $env:_ARGCOMPLETE_SUPPRESS_SPACE = 0
    $env:_ARGCOMPLETE_IFS = "`n"
    $env:_ARGCOMPLETE_SHELL = 'powershell'
    az 2>&1 | Out-Null
    Get-Content $completion_file | Sort-Object | ForEach-Object {
        [System.Management.Automation.CompletionResult]::new($_, $_, "ParameterValue", $_)
    }
    Remove-Item $completion_file, Env:\_ARGCOMPLETE_STDOUT_FILENAME, Env:\ARGCOMPLETE_USE_TEMPFILES, Env:\COMP_LINE, Env:\COMP_POINT, Env:\_ARGCOMPLETE, Env:\_ARGCOMPLETE_SUPPRESS_SPACE, Env:\_ARGCOMPLETE_IFS, Env:\_ARGCOMPLETE_SHELL
}

# cloudflare warp cli completions
# warp-cli generate-completions powershell | Out-String | Invoke-Expression

Also, I tried installing AppControlManager using the GUI, it installed fine but when I tried to run it, I got the following error. I tried running with admin privileges but same error.

[Window Title]
C:\Program Files\WindowsApps\AppControlManager_1.8.2.0_x64__sadt7br7jpt02\AppControlManager.exe

[Content]
C:\Program Files\WindowsApps\AppControlManager_1.8.2.0_x64__sadt7br7jpt02\AppControlManager.exe

A referral was returned from the server.

[OK]

@HotCakeX
Copy link
Owner

HotCakeX commented Jan 7, 2025

Thanks for checking and confirming,

the problem with A referral was returned from the server is because these requirements are not satisfied:

image

@agpt8
Copy link
Contributor Author

agpt8 commented Jan 7, 2025

Interesting, maybe a pre-check can be added to the install option or as a pre-install step that would check if the requirements were met and if not, display the steps (or refer to them) on how to get the machine to the desired state.

@HotCakeX
Copy link
Owner

HotCakeX commented Jan 7, 2025

You're right, i'll do that!

@HotCakeX
Copy link
Owner

HotCakeX commented Jan 7, 2025

@agpt8 Good news, completely fixed this issue. You will be able to use all features of the Harden Windows Security, including getting toast notifications when actions are completed, without the need to make any changes to your PowerShell profile.

Also added a dialog box when that incompatible policy is detected. The changes are in this PR if you want to review: #514

I'll release a new version of the module soon that will include this change but i'm waiting to add one more new feature before doing that so it might take a day or two, hope that's okay.

Thanks again for reporting the problem!

HotCakeX added a commit that referenced this issue Jan 7, 2025
The module will not detect if there was a problem loading its dlls and if it was, reloads PowerShell with -NoProfile switch to fix it.

Also a new message will be shown when installing the AppControl Manager and there is an incompatible policy on the system.

Fixes this issue: #513
@HotCakeX
Copy link
Owner

HotCakeX commented Jan 8, 2025

Just released the update: https://github.com/HotCakeX/Harden-Windows-Security/releases/tag/Hardening-Module-v.0.7.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working
Projects
None yet
2 participants