Closed HotCakeX closed 3 months ago
Getting this error after updating
@agpt8 What do you see when you run these
Import-module -Name 'Harden-Windows-Security-Module'
Get-Error
@agpt8 Can you temporarily disable the "oh my posh" addon that you are using and then try again? You might have to restart the terminal or your PC, I haven't used it so I'm not sure what it changes.
btw there hasn't been any changes to the commands and parameters, Confirm-SystemCompliance
has no -GUI
parameter. The GUI is available just like before with Protect-WindowsSecurity -GUI
.
@agpt8 Something in your PowerShell environment is loading some dlls that is interfering with the module, I don't know what that is, try this command, it might show what's already loaded that is causing it
Get-Module
This is all I have
Update: It has something to do with the first three modules that are loaded. I renamed the powershell profile file so that it does not read it, then tried again. Only PSReadLine was loaded. When I tried to run the module with GUI again, it loaded just fine. This is quite odd as I have been using the module normally with everything loading in the background. I guess this update clashes with something which is causing errors
Thanks, so for comparison this is what i have by default.
Currently what I'm suspecting is either PowerToys' CommandNotFound extension or Winget's PowerShell module is the source of the interference.
The reason it used to work before but now it has interference is because of the 5 new Microsoft DLLs that are included. The error basically means something else already loaded those DLLs in the current session so when the Harden Windows Security module tries to load them again, it displays an error.
I'll try to match your environment, reproduce the error and then think about a solution I can implement in the next update.
Another error: I tried the Confirm and Verify tab on the GUI, pressed the play button, it showed loading and now it seems stuck. The animations on the button are stuck and I cannot click anything on the GUI. Had to force it to close, the window controls seem stuck as well.
That must be the Defender scanning the new module files, try again, it should work
I tried again, interestingly, I got the following on the terminal side:
PowerShell 7.4.5
PS C:\Users\ayush> Protect-WindowsSecurity -GUI
MethodInvocationException: Exception calling "Run" with "1" argument(s): "One or more errors occurred. (PowerShell script execution failed: Error:
Class not registered Category: NotSpecified Target: Script StackTrace: at <ScriptBlock>, <No file>: line 2 Exception
Type: System.Runtime.InteropServices.COMException StackTrace: at
System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord))"
ErrorRecord : Exception calling "Run" with "1" argument(s): "One or more errors occurred. (PowerShell
script execution failed: Error: Class not registered
Category: NotSpecified
Target:
Script StackTrace: at <ScriptBlock>, <No file>: line 2
Exception Type: System.Runtime.InteropServices.COMException
StackTrace: at
System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord
errorRecord))"
WasThrownFromThrowStatement : False
TargetSite : Void CheckActionPreference(System.Management.Automation.Language.FunctionContext,
System.Exception)
Message : Exception calling "Run" with "1" argument(s): "One or more errors occurred. (PowerShell
script execution failed: Error: Class not registered
Category: NotSpecified
Target:
Script StackTrace: at <ScriptBlock>, <No file>: line 2
Exception Type: System.Runtime.InteropServices.COMException
StackTrace: at
System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord
errorRecord))"
Data : {[System.Management.Automation.Interpreter.InterpretedFrameInfo,
System.Management.Automation.Interpreter.InterpretedFrameInfo[]]}
InnerException : System.AggregateException: One or more errors occurred. (PowerShell script execution
failed: Error: Class not registered
Category: NotSpecified
Target:
Script StackTrace: at <ScriptBlock>, <No file>: line 2
Exception Type: System.Runtime.InteropServices.COMException
StackTrace: at
System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord
errorRecord))
---> System.InvalidOperationException: PowerShell script execution failed: Error: Class
not registered
Category: NotSpecified
Target:
Script StackTrace: at <ScriptBlock>, <No file>: line 2
Exception Type: System.Runtime.InteropServices.COMException
StackTrace: at
System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord
errorRecord)
at HardenWindowsSecurity.PowerShellExecutor.ExecuteScript(String script, Boolean
returnOutput)
at HardenWindowsSecurity.WindowsFeatureChecker.GetCapabilityState(String
capabilityName)
at HardenWindowsSecurity.WindowsFeatureChecker.CheckWindowsFeatures()
at HardenWindowsSecurity.ConfirmSystemComplianceMethods.<>c.<VerifyOptionalWindowsFeat
ures>b__14_0()
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.ConfirmSystemComplianceMethods.RunComplianceMethodsInParallel
Async(String[] methodNames)
--- End of inner exception stack trace ---
at HardenWindowsSecurity.ConfirmSystemComplianceMethods.OrchestrateComplianceChecks(St
ring[] methodNames)
at HardenWindowsSecurity.InvokeConfirmation.Invoke(String[] Categories)
at HardenWindowsSecurity.GUIMain.NavigationVM.<>c.<Confirm>b__4_4()
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__1>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 : 363
OffsetInLine : 17
HistoryId : 1
ScriptName : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.5.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.5.5\Co
re\Protect-WindowsSecurity.psm1:363 char:17
+ … [System.Void] [HardenWindowsSecurity.GUIMain]::app.Run([H …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.5.5\Core
PSCommandPath : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.5.5\Core\
Protect-WindowsSecurity.psm1
InvocationName :
PipelineLength : 0
PipelinePosition : 0
ExpectingInput : False
CommandOrigin : Internal
DisplayScriptPosition :
PS C:\Users\ayush>
Also, a few more observations, the confirm and verify tab only shows loading for me (the animations and regular window interactivity works), though the Protect tab shows a few logs that seem to be for the Confirm task? These should be on the Confirm tab right?
And after it completes verifying, the Confirm tab does not show anything though, just Loading...
Also, the categories on the Protect tab have the tooltips showing way to quickly on hover, a slight pause and delay on hover would be better imo. And the scrolling of the category list is too quick on the precision trackpad, even a very slight scroll would instantly scroll the list to the end. Very hard to control it without grabbing and manually scrolling.
Oh and now the window is stuck again. Completely non-interactive.
Sorry for badgering you, but the Confirm-SystemCompliance cli also throws error
Here is the full trace:
PS C:\Users\ayush> Confirm-SystemCompliance
Exception: Exception calling "Invoke" with "1" argument(s): "One or more errors occurred. (PowerShell script execution failed:
Error: Class not registered Category: NotSpecified Target: Script StackTrace: at <ScriptBlock>, <No file>: line 2
Exception Type: System.Runtime.InteropServices.COMException StackTrace: at
System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord))"
PS C:\Users\ayush> Get-Error
Exception :
Type : System.Management.Automation.MethodInvocationException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Exception calling "Invoke" with "1" argument(s): "One or more errors occurred. (PowerShell
script execution failed: Error: Class not registered
Category: NotSpecified
Target:
Script StackTrace: at <ScriptBlock>, <No file>: line 2
Exception Type: System.Runtime.InteropServices.COMException
StackTrace: at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord))"
HResult : -2146233087
CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : AggregateException
InvocationInfo :
ScriptLineNumber : 158
OffsetInLine : 13
HistoryId : 1
ScriptName : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.5.
5\Core\Confirm-SystemCompliance.psm1
Line : [HardenWindowsSecurity.InvokeConfirmation]::Invoke($Categories)
Statement : [HardenWindowsSecurity.InvokeConfirmation]::Invoke($Categories)
PositionMessage : At C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0
.5.5\Core\Confirm-SystemCompliance.psm1:158 char:13
+ [HardenWindowsSecurity.InvokeConfirmation]::Invoke($Categ …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot :
C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.5.5\Core
PSCommandPath : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.5.
5\Core\Confirm-SystemCompliance.psm1
CommandOrigin : Internal
ScriptStackTrace : at Confirm-SystemCompliance<Process>, C:\Users\ayush\OneDrive\Documents\PowerShell\Modu
les\Harden-Windows-Security-Module\0.5.5\Core\Confirm-SystemCompliance.psm1: line 158
at <ScriptBlock>, <No file>: line 1
WasThrownFromThrowStatement : True
TargetSite :
Name : CheckActionPreference
DeclaringType : [System.Management.Automation.ExceptionHandlingOps]
MemberType : Method
Module : System.Management.Automation.dll
Message : Exception calling "Invoke" with "1" argument(s): "One or more errors occurred.
(PowerShell script execution failed: Error: Class not registered
Category: NotSpecified
Target:
Script StackTrace: at <ScriptBlock>, <No file>: line 2
Exception Type: System.Runtime.InteropServices.COMException
StackTrace: at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord))"
Data : System.Collections.ListDictionaryInternal
InnerException :
Type : System.AggregateException
InnerExceptions :
Type : System.InvalidOperationException
TargetSite :
Name : ExecuteScript
DeclaringType : [HardenWindowsSecurity.PowerShellExecutor]
MemberType : Method
Module : bfiqgimx.vn5.dll
Message : PowerShell script execution failed: Error: Class not registered
Category: NotSpecified
Target:
Script StackTrace: at <ScriptBlock>, <No file>: line 2
Exception Type: System.Runtime.InteropServices.COMException
StackTrace: at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
Source : bfiqgimx.vn5
HResult : -2146233079
StackTrace :
at HardenWindowsSecurity.PowerShellExecutor.ExecuteScript(String script, Boolean returnOutput)
at HardenWindowsSecurity.WindowsFeatureChecker.GetCapabilityState(String capabilityName)
at HardenWindowsSecurity.WindowsFeatureChecker.CheckWindowsFeatures()
at HardenWindowsSecurity.ConfirmSystemComplianceMethods.<>c.<VerifyOptionalWindowsFeatures>b__14_0()
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.ConfirmSystemComplianceMethods.RunComplianceMethodsInParallelAsync(String[] methodNames)
Message : One or more errors occurred. (PowerShell script execution failed: Error: Class not registered
Category: NotSpecified
Target:
Script StackTrace: at <ScriptBlock>, <No file>: line 2
Exception Type: System.Runtime.InteropServices.COMException
StackTrace: at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord))
TargetSite :
Name : OrchestrateComplianceChecks
DeclaringType : [HardenWindowsSecurity.ConfirmSystemComplianceMethods]
MemberType : Method
Module : bfiqgimx.vn5.dll
InnerException :
Type : System.InvalidOperationException
TargetSite :
Name : ExecuteScript
DeclaringType : [HardenWindowsSecurity.PowerShellExecutor]
MemberType : Method
Module : bfiqgimx.vn5.dll
Message : PowerShell script execution failed: Error: Class not registered
Category: NotSpecified
Target:
Script StackTrace: at <ScriptBlock>, <No file>: line 2
Exception Type: System.Runtime.InteropServices.COMException
StackTrace: at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
Source : bfiqgimx.vn5
HResult : -2146233079
StackTrace :
at HardenWindowsSecurity.PowerShellExecutor.ExecuteScript(String script, Boolean returnOutput)
at HardenWindowsSecurity.WindowsFeatureChecker.GetCapabilityState(String capabilityName)
at HardenWindowsSecurity.WindowsFeatureChecker.CheckWindowsFeatures()
at HardenWindowsSecurity.ConfirmSystemComplianceMethods.<>c.<VerifyOptionalWindowsFeatures>b__14_0()
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.ConfirmSystemComplianceMethods.RunComplianceMethodsInParallelAsync(String[] methodNames)
Source : bfiqgimx.vn5
HResult : -2146233088
StackTrace :
at HardenWindowsSecurity.ConfirmSystemComplianceMethods.OrchestrateComplianceChecks(String[] methodNames)
at HardenWindowsSecurity.InvokeConfirmation.Invoke(String[] Categories)
at CallSite.Target(Closure, CallSite, Type, Object)
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 : AggregateException
InvocationInfo :
ScriptLineNumber : 158
OffsetInLine : 13
HistoryId : 1
ScriptName : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.5.5\Core\C
onfirm-SystemCompliance.psm1
Line : [HardenWindowsSecurity.InvokeConfirmation]::Invoke($Categories)
Statement : [HardenWindowsSecurity.InvokeConfirmation]::Invoke($Categories)
PositionMessage : At C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.5.5\Cor
e\Confirm-SystemCompliance.psm1:158 char:13
+ [HardenWindowsSecurity.InvokeConfirmation]::Invoke($Categ …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.5.5\Core
PSCommandPath : C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Harden-Windows-Security-Module\0.5.5\Core\C
onfirm-SystemCompliance.psm1
CommandOrigin : Internal
ScriptStackTrace : at Confirm-SystemCompliance<Process>, C:\Users\ayush\OneDrive\Documents\PowerShell\Modules\Hard
en-Windows-Security-Module\0.5.5\Core\Confirm-SystemCompliance.psm1: line 158
at <ScriptBlock>, <No file>: line 1
PS C:\Users\ayush>
Not at all, i'm glad you let me know about these errors, but it's all okay, I've found the root cause of all of them and i apologize for letting them slip, i'll explain why
I've rolled back the version file in the repo root that points to the new version, so that auto updating won't happen, i will release the new version with the fixes very soon.
P.S about the tooltips showing up quickly, I Intentionally made it that way because the default timing was too slow and I wanted users to quickly get the information about each category as they hover over them.
@agpt8 released v0.5.6, please try again and let me know how it goes https://github.com/HotCakeX/Harden-Windows-Security/releases/tag/Hardening-Module-v.0.5.6
Everything looks good now! Confirm and Verify list is also populating in the GUI. There are a few observations and suggestions I would like to highlight for the GUI. I'll open a discussion later today for all of those. Thanks for the quick fix!
What's New
Added Compliance checking and system auditing functionality to the GUI with built-in search functionality.
Added Sidebar tabbed experience with animation for ease of use. It has virtually unlimited space for new features and pages with scrollable style.
Using MVVM design pattern.
Native WPF GUI with no 3rd party dependency or any compiled binaries.
When ARM hardware is detected, all process mitigations will be skipped. More info here. If you have ARM hardware and want to contribute to this project, you can help me verify each process mitigation on your ARM hardware so I can enable the ones that are compatible.
The experience and logic for enabling logging has been improved.
You can now manually enter the path where the logs will be saved to as well. Previously, you'd only have to use the button on the GUI to browse for one.
Added custom tooltips for each category and sub-category in the protection tab with small meaningful details to help you decide which option to choose.
Required PowerShell version has been increased from 7.4.2 to 7.4.4. The Harden Windows Security heavily relies on the latest .NET components shipped with PowerShell, that's why you don't need to install .NET runtime separately.
When logging is enabled, the logs are written to the file in real time instead of at the end of the operation.
Significantly improved the toast notifications experience, they are now modern Windows 11 style toast notifications. Due to this improved experience, 5 official Microsoft-Signed DLLs are bundled with the Harden Windows Security program. Links to them can be found below:
The Harden Windows Security program can now be fully used in both Visual Studio (native C#) and Visual Studio Code (native PowerShell). Its hybrid design allows it to be highly interoperable.
What's Next
Unprotect-WindowsSecurity
will be added to the GUI.Attack Surface Reduction rules will be individually configurable in a new section in the GUI.
BitLocker enrollment and activation through the GUI.
And more.
Resolves #318