How to programatically re-enable documents in the MS Office list of disabled files

前端 未结 5 613
栀梦
栀梦 2020-12-18 10:18

MS Office programs keep a list of disabled files that have caused errors when previously opened. A user can remove documents from this list by accessing the list through the

5条回答
  •  臣服心动
    2020-12-18 11:09

    Here is a Powershell Script that I threw together to fit a similar problem I was having with MS-Access 2013 on Win7

    #RemoveOfficeDisabledItem.ps1
    #command line: 
    #   powershell -executionpolicy unrestricted -file ".\RemoveOfficeDisabledItem.ps1"
    
    #Update these variables to suit your situation
    $OfficeVersion="15.0"
    $OfficeApp="Access"
    $FileName="My Blocked File.mdb"
    
    #Converts the File Name string to UTF16 Hex
    $FileName_UniHex=""
    [System.Text.Encoding]::ASCII.GetBytes($FileName.ToLower()) | %{$FileName_UniHex+="{0:X2}00" -f $_}
    
    #Tests to see if the Disabled items registry key exists
    $RegKey=(gi "HKCU:\Software\Microsoft\Office\${OfficeVersion}\${OfficeApp}\Resiliency\DisabledItems\")
    if($RegKey -eq $NULL){exit}
    
    #Cycles through all the properties and deletes it if it contains the file name.
    foreach ($prop in $RegKey.Property) {
       $Val=""
       ($RegKey|gp).$prop | %{$Val+="{0:X2}" -f $_}
       if($Val.Contains($FileName_UniHex)){$RegKey|Remove-ItemProperty -name $prop}
    }
    

提交回复
热议问题