使用Powershell /批处理命令

时间:2020-02-10 03:11:26

标签: powershell batch-file ms-word patch

是否存在使用Batch / PowerShell命令卸载MS Word KB文章的干净方法?

背景:

我一直在尝试卸载一个KB文章(KB4475558)MS Word2013。作为手动团队解决方案的一部分,谁想要卸载所有新安装的KB文章。我已成功尝试安装多个知识库文章。但是卸载一直很棘手。

到目前为止尝试过,

方法1: wusa /uninstall /KB:4475558 wusa.exe /uninstall /kb:4475558 /norestart /quiet ----它显示“此操作仅对当前安装的产品有效”错误。

方法2:使用GUID

Msiexec /I {90150000-006E-0401-1000-0000000FF1CE} MSIPATCHREMOVE={80BC2A33-0ADF-4731-AC75-046BA9B6B7AF} /qb ----它显示“此操作仅对当前安装的产品有效”错误。

方法3:

通过下面的链接使用Microsoft.Update.Searcher,

PowerShell: How to find and uninstall a MS Office Update

-不起作用。

在这些问题上,您能帮我吗?

1:我已经手动安装了这些知识库文章,可以手动将其卸载:但是通过脚本,它显示了上述错误。为什么会这样?

2:我可能会缺少其他方法吗?

注意: MS Office不仅安装了MS Word和共享点,而且我的计算机上没有可用的Trail版本。 我还尝试过一次重新启动计算机,但无济于事。

任何帮助都会大有帮助!谢谢

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用来解析注册表卸载键中的卸载字符串? 我通常不会推荐这种方法,但是它总比没有好。

@(For /F "Delims=" %%G In (
    '^""%__AppDir__%reg.exe" Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /S /F "(KB4475558)" /D 2^>NUL^|Find "{"^"'
)Do @For /F "Tokens=2*" %%H In ('^""%__AppDir__%reg.exe" Query "%%G" /V "UninstallString" 2^>NUL^"')Do @Echo(%%I)&Pause

如果对结果满意,可以修改代码以尝试将其卸载,(可能需要运行脚本或命令“以管理员身份”)

来自

@For /F "Delims=" %%G In (
    '^""%__AppDir__%reg.exe" Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /S /F "(KB4475558)" /D 2^>NUL^|Find "{"^"'
)Do @For /F "Tokens=2*" %%H In ('^""%__AppDir__%reg.exe" Query "%%G" /V "UninstallString" 2^>NUL^"')Do @%%I

或来自

For /F "Delims=" %G In ('""%__AppDir__%reg.exe" Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /S /F "KB4475558" /D 2>NUL|Find "{""')Do @For /F "Tokens=2*" %H In ('""%__AppDir__%reg.exe" Query "%G" /V "UninstallString" 2>NUL"')Do @Echo(%I

如果您尝试对Office产品的所有KB更新进行此操作,则可能会使您接近:

@(For /F "Delims=" %%G In (
    '^""%__AppDir__%reg.exe" Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /S /F "0FF1CE}_Office" /K 2^>NUL^|Find "{"^"'
)Do @For /F "Tokens=2*" %%H In ('^""%__AppDir__%reg.exe" Query "%%G" /V "UninstallString" 2^>NUL^"')Do @Echo(%%I)&Pause

如果对结果满意,可以修改代码以尝试将其卸载,(可能需要运行脚本或命令“以管理员身份”)

来自

@(For /F "Delims=" %%G In (
    '^""%__AppDir__%reg.exe" Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /S /F "0FF1CE}_Office" /K 2^>NUL^|Find "{"^"'
)Do @For /F "Tokens=2*" %%H In ('^""%__AppDir__%reg.exe" Query "%%G" /V "UninstallString" 2^>NUL^"')Do @Echo(%%I)&Pause

或来自

For /F "Delims=" %G In ('""%__AppDir__%reg.exe" Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /S /F "0FF1CE}_Office" /K 2>NUL|Find "{""')Do @For /F "Tokens=2*" %H In ('""%__AppDir__%reg.exe" Query "%G" /V "UninstallString" 2>NUL"')Do @%I

请注意,上面的示例仅用于解析注册表项HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall。可能还有其他位置,例如HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall也会保留您需要的信息。