LogMsg "Fix-WindowsScriptingComponents.ps1"

## List of all scripting component DLL files
$DLL_FILES = @("${Env:WINDIR}\system32\vbscript.dll",
               "${Env:WINDIR}\system32\jscript.dll",
               "${Env:WINDIR}\system32\dispex.dll",
               "${Env:WINDIR}\system32\scrobj.dll",
               "${Env:WINDIR}\system32\scrrun.dll",
               "${Env:WINDIR}\system32\wshext.dll"
               "${Env:WINDIR}\system32\wshom.ocx",
               "${Env:WINDIR}\syswow64\vbscript.dll",
               "${Env:WINDIR}\syswow64\jscript.dll",
               "${Env:WINDIR}\syswow64\dispex.dll",
               "${Env:WINDIR}\syswow64\scrobj.dll",
               "${Env:WINDIR}\syswow64\scrrun.dll",
               "${Env:WINDIR}\syswow64\wshext.dll",
               "${Env:WINDIR}\syswow64\wshom.ocx")

## Unregister all DLLs
ForEach ($dll in $DLL_FILES)
{
    If ( Test-Path $dll )
    {
        If ( $dll -Match "syswow64" ) { $REGSVR32 = "${Env:WINDIR}\syswow64\regsvr32" } Else { $REGSVR32 = "regsvr32" }
        LogMsg "Unregister: ${dll}"
        Try { Start-Process "${REGSVR32}" -ArgumentList "/u /s ${dll}" -Wait }
        Catch { LogErr $_.Exception.Message }
    }
}

## Register all DLLs
ForEach ($dll in $DLL_FILES)
{
    If ( Test-Path $dll )
    {
        If ( $dll -Match "syswow64" )
        { $REGSVR32 = "${Env:WINDIR}\syswow64\regsvr32" } Else { $REGSVR32 = "regsvr32" }
        LogMsg "Register: ${dll}"
        Try { Start-Process "${REGSVR32}" -ArgumentList "/s ${dll}" -Wait }
        Catch { LogErr $_.Exception.Message }
    }
}