Adobe向我提供了一个XML列表,列出了哪些进程将与每个安装程序构建发生冲突,但无法自动使用此类文件来结束这些任务。
这就是我想做的:
我对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>发布于 2018-06-18 21:59:41
您的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}
}https://stackoverflow.com/questions/50917703
复制相似问题