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

谁说我不能喝 提交于 2019-12-19 09:37:51

问题


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 program menu and selecting a document to be re-enabled. (http://support.microsoft.com/kb/286017)

The question is: How can this re-enabling of documents be accomplished programmatically, without interaction with the gui?


回答1:


Consolidating previous answers and expounding upon them here.

Office products store disabled items in the registry under keys named HKEY_CURRENT_USER\Software\Microsoft\Office\<version>\<product>\Resiliency\DisabledItems. For example, Excel 2010's disabled list is under HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\Resiliency\DisabledItems.

Each disabled item is stored as a randomly-named key of type REG_BINARY. The format of the byte array is:

  • bytes 0-3 : ??? (perhaps a 32-bit uint type code, 1 = COM Addin)
  • bytes 4-7 : 32-bit uint length (in bytes) for the first string (path)
  • bytes 8-11 : 32-bit uint length (in bytes) for the second string (description)
  • bytes 12-end : two strings of unicode characters, the byte length for each of which is stored in the uints above



回答2:


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}
}



回答3:


BAT script to re-enable all "disabled items" in Excel 2016.
Disabled items are found in Excel->File->Options->Addins->Manage->Disabled items.

:: Deletes all values under the key.  
REG DELETE HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Excel\Resiliency\DisabledItems /va /f 

Fyi on params:
/va Delete all values under this key.
/f Forces the deletion without prompt.

PS. I have a bunch of workbooks that run macros with a task scheduler. Excel would randomly add workbooks that crashed onto the disabled items list. So running this BAT script daily resolves it OK.




回答4:


Regarding MS Office XP (2002) MSWord the list of disabled documents is kept as randomly named binary values under the key: [HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Word\Resiliency\DisabledItems]

So deleting the values under the "DisabledItems" key for every user probably will do the trick.

Is there something more to it? I don't know - yet.




回答5:


There is a good article about how Office handles COMAddins at codeproject. Normal Addins are handled equally and the system was kept unchanged so far (up to Office 2013). As far as I found out. The randomly named value contains a byte-array of unicode characters, separated by null-strings. I could not find out about all the entries in the null-separated array of values. However index (3) contains the filename of the ADDIn and index (4) contains a description of the ADDIn if available.

So one should read the values and ask the user to reinstall the addins before deleting the registry keys as Luie wrote back in 2009.



来源:https://stackoverflow.com/questions/751048/how-to-programatically-re-enable-documents-in-the-ms-office-list-of-disabled-fil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!