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]: 'System.Dynamic.ExpandoObject' does not contain a definition for 'SmartAppControlState' #338

Closed JuliusBairaktaris closed 2 months ago

JuliusBairaktaris commented 2 months 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

When running the following command on a clean install of Windows 11 23H2 (Build: 22631.4112):

(irm 'https://raw.githubusercontent.com/HotCakeX/Harden-Windows-Security/main/Harden-Windows-Security.ps1')+'P'|iex

I encounter the following error:

MethodInvocationException: Exception calling "Run" with "1" argument(s): "'System.Dynamic.ExpandoObject' does not contain a definition for
'SmartAppControlState'"

ErrorRecord                 : Exception calling "Run" with "1" argument(s): "'System.Dynamic.ExpandoObject' does not
                              contain a definition for 'SmartAppControlState'"
WasThrownFromThrowStatement : False
TargetSite                  : Void CheckActionPreference(System.Management.Automation.Language.FunctionContext,
                              System.Exception)
Message                     : Exception calling "Run" with "1" argument(s): "'System.Dynamic.ExpandoObject' does not
                              contain a definition for 'SmartAppControlState'"
Data                        : {[System.Management.Automation.Interpreter.InterpretedFrameInfo,
                              System.Management.Automation.Interpreter.InterpretedFrameInfo[]]}
InnerException              : Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Dynamic.ExpandoObject'
                              does not contain a definition for 'SmartAppControlState'
                                 at CallSite.Target(Closure, CallSite, Object)
                                 at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
                                 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.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\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.0\Core\Protect-W
                        indowsSecurity.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\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.0\Core\Protec
                        t-WindowsSecurity.psm1:364 char:17
                        + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
                        +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot          : C:\Users\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.0\Core
PSCommandPath         : C:\Users\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.0\Core\Protect-W
                        indowsSecurity.psm1
InvocationName        :
PipelineLength        : 0
PipelinePosition      : 0
ExpectingInput        : False
CommandOrigin         : Internal
DisplayScriptPosition :

Environment Details:

Error Details

Exception             :
    Type           : System.Management.Automation.MethodInvocationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Exception calling "Run" with "1" argument(s): "'System.Dynamic.ExpandoObject' does
not contain a definition for 'SmartAppControlState'"
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : RuntimeBinderException
        InvocationInfo        :
            ScriptLineNumber : 364
            OffsetInLine     : 17
            HistoryId        : 1
            ScriptName       : C:\Users\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.
6.0\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\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module
\0.6.0\Core\Protect-WindowsSecurity.psm1:364 char:17
                               + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
                               +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            PSScriptRoot     :
C:\Users\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.0\Core
            PSCommandPath    : C:\Users\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.
6.0\Core\Protect-WindowsSecurity.psm1
            CommandOrigin    : Internal
        ScriptStackTrace      : at Protect-WindowsSecurity<Begin>, C:\Users\juliu\Documents\PowerShell\Modul
es\Harden-Windows-Security-Module\0.6.0\Core\Protect-WindowsSecurity.psm1: line 364
                                at <ScriptBlock>, <No file>: line 7
    TargetSite     :
        Name          : CheckActionPreference
        DeclaringType : [System.Management.Automation.ExceptionHandlingOps]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message        : Exception calling "Run" with "1" argument(s): "'System.Dynamic.ExpandoObject' does not
contain a definition for 'SmartAppControlState'"
    Data           : System.Collections.ListDictionaryInternal
    InnerException :
        Type       : Microsoft.CSharp.RuntimeBinder.RuntimeBinderException
        TargetSite : System.Object CallSite.Target(System.Runtime.CompilerServices.Closure,
System.Runtime.CompilerServices.CallSite, System.Object)
        Message    : 'System.Dynamic.ExpandoObject' does not contain a definition for 'SmartAppControlState'
        Data       : System.Collections.ListDictionaryInternal
        Source     : Anonymously Hosted DynamicMethods Assembly
        HResult    : -2146233088
        StackTrace :
   at CallSite.Target(Closure, CallSite, Object)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
   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.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 : RuntimeBinderException
InvocationInfo        :
    ScriptLineNumber : 364
    OffsetInLine     : 17
    HistoryId        : 1
    ScriptName       : C:\Users\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.0\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\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.0\C
ore\Protect-WindowsSecurity.psm1:364 char:17
                       + …             [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
                       +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Users\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.0\Core
    PSCommandPath    : C:\Users\juliu\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.6.0\Core
\Protect-WindowsSecurity.psm1
    CommandOrigin    : Internal
ScriptStackTrace      : at Protect-WindowsSecurity<Begin>, C:\Users\juliu\Documents\PowerShell\Modules\Harde
n-Windows-Security-Module\0.6.0\Core\Protect-WindowsSecurity.psm1: line 364
                        at <ScriptBlock>, <No file>: line 7
HotCakeX commented 2 months ago

Thanks for reporting it, I've fixed it and will release the update tomorrow along with other improvements. The fix involved removing any assumption that these properties exist in the first place.

It's strange thought that this is a thing. When you run Get-MpComputerStatus, you don't see SmartAppControlState in the result?

ghost commented 2 months ago

I have the same error as @JuliusBairaktaris. When I run Get-MpComputerStatus, I do not see SmartAppControlState.

HotCakeX commented 2 months ago

@skeleton2464 @JuliusBairaktaris Fixed in version 0.6.1, please try any command you were using again so the module can automatically update to the latest version and then you'll be able to use it without any problems.

https://github.com/HotCakeX/Harden-Windows-Security/releases/tag/Hardening-Module-v.0.6.1

JuliusBairaktaris commented 2 months ago

When you run Get-MpComputerStatus, you don't see SmartAppControlState in the result?

I do

But I can confirm it's fixed now. Great GUI, by the way. It would be nice if you could add an extra option similar to the ASR rules for SmartScreen block / block and warn, since this is a setting I always flip manually after applying your script.

HotCakeX commented 2 months ago

Thank you, i'll add it in a future update.