用于杀死Adobe CC冲突列表

时间:2018-06-18 21:27:21

标签: arrays powershell object adobe ps

Adob​​e向我提供了一个XML列表,列出了哪些进程会与每个安装程序构建冲突,但无法自动使用此类文件来结束这些任务。

这就是我要做的事情:

  1. 从他们生成的XML文件中导入冲突进程列表
  2. 与当前正在运行的进程列表进行比较,
  3. 杀死那些匹配的人。
  4. 我对Powershell来说相当新,但我可以随意找到自己的方式。这个让我摸不着头脑......

    来自XML文件的数组很好,对于正在运行的进程数组似乎也是如此,但是比较两者并在匹配时杀死进程似乎没有工作......

    下面我将添加我的代码,以及adobe的安装程序构建生成的示例xml文件。任何帮助是极大的赞赏。希望这是愚蠢的事情,我90%的方式,但我不确定。该脚本不会产生任何错误,但也不会做任何事情,所以,是的......是的。

    在预先感谢任何提示或其他寻求解决此问题的灵魂,以完成我已经开始的事情......

    [xml]$XmlDocument = Get-Content -Path .\ConflictingProcessList.xml
    $ConflictProcesses = $XmlDocument.ConflictingProcessList.Product.conflictingProcesses.ConflictingProcess
    $ProcessList = gwmi Win32_Process
    
    foreach ($ProcessDisplayName in $ConflictProcesses)
    {
        foreach ($name in $ProcessList)
        {
            Where-Object { $ConflictProcesses.RelativePath -contains $ProcessList.ProcessName } | % { Stop-Process ($ProcessList.ProcessID) }
        }
        $ProcessList = gwmi Win32_Process
    }
    

    以下是Acrobat Pro 2018 CC安装程序的示例XML:

    <ConflictingProcessList>
        <Product>
            <name>Creative Cloud</name>
            <conflictingProcesses>
                <ConflictingProcess>
                    <ProcessDisplayName>PDapp.exe</ProcessDisplayName>
                    <RelativePath>%CommonProgramFiles(x86)%\Adobe\OOBE\PDApp\CCP\CreativeCloudPackager.exe</RelativePath>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>Adobe Application Manager (Updater).exe</ProcessDisplayName>
                    <RelativePath>%CommonProgramFiles(x86)%\Adobe\OOBE\PDApp\UWA\Adobe Application Manager (Updater).exe</RelativePath>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>PDapp.exe</ProcessDisplayName>
                    <RelativePath>%CommonProgramFiles(x86)%\Adobe\OOBE\PDApp\core\PDapp.exe</RelativePath>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>AAM Updates Notifier.exe</ProcessDisplayName>
                    <RelativePath>%CommonProgramFiles(x86)%\Adobe\OOBE\PDApp\UWA\AAM Updates Notifier.exe</RelativePath>
                </ConflictingProcess>
            </conflictingProcesses>
        </Product>
        <Product>
            <name>Acrobat DC</name>
            <conflictingProcesses>
                <ConflictingProcess>
                    <ProcessDisplayName>Adobe Acrobat DC</ProcessDisplayName>
                    <RelativePath>[INSTALLDIR]\Acrobat DC\Acrobat\Acrobat.exe</RelativePath>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>Microsoft Outlook</ProcessDisplayName>
                    <RelativePath/>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>Adobe Acrobat X</ProcessDisplayName>
                    <RelativePath>[INSTALLDIR]\Acrobat 10.0\Acrobat\Acrobat.exe</RelativePath>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>Microsoft PowerPoint</ProcessDisplayName>
                    <RelativePath/>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>Visio</ProcessDisplayName>
                    <RelativePath/>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>Microsoft Excel</ProcessDisplayName>
                    <RelativePath/>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>Adobe Acrobat 2015</ProcessDisplayName>
                    <RelativePath>[INSTALLDIR]\Acrobat 2015\Acrobat\Acrobat.exe</RelativePath>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>Adobe Acrobat XI</ProcessDisplayName>
                    <RelativePath>[INSTALLDIR]\Acrobat 11.0\Acrobat\Acrobat.exe</RelativePath>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>MS Project</ProcessDisplayName>
                    <RelativePath/>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>Microsoft Word</ProcessDisplayName>
                    <RelativePath/>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>Adobe Acrobat 2017</ProcessDisplayName>
                    <RelativePath>[INSTALLDIR]\Acrobat 2017\Acrobat\Acrobat.exe</RelativePath>
                </ConflictingProcess>
                <ConflictingProcess>
                    <ProcessDisplayName>AutoCAD</ProcessDisplayName>
                    <RelativePath/>
                </ConflictingProcess>
            </conflictingProcesses>
        </Product>
    </ConflictingProcessList>
    

1 个答案:

答案 0 :(得分:1)

您的foreach循环是多余的,因为您实际上从未实际引用$ProcessDisplayName$name局部变量。此外,内部管道(以Where-Object开头)不会产生任何结果,因为您实际上并未向其提供任何数据。

我建议迭代$ConflictProcesses并杀死任何匹配的过程,如下所示:

foreach($ConflictProcess in $ConflictProcesses){
    # Extract file name
    $FileName = $ConflictProcess.RelativePath |Split-Path -Leaf

    # Now grab the processes with that file name and kill them 
    Get-WmiObject Win32_Process |Where-Object { $_.Name -eq $FileName } |Stop-Process -Id {$_.ProcessId}
}