我有一个简单的PowerShell代码段来列出已安装的Windows软件和版本:
$msi = New-Object -ComObject WindowsInstaller.Installer
$msi.GetType().InvokeMember('ProductsEx', 'GetProperty', $null, $msi, ('', 's-1-1-0', 7)) | select @{ name='name'; expression={$_.GetType().InvokeMember('InstallProperty', 'GetProperty', $null, $_, ('ProductName')) } }, @{ name='version'; expression={$_.GetType().InvokeMember('InstallProperty', 'GetProperty', $null, $_, ('VersionString'))} }
以普通用户身份运行时,结果如下: -
PS C:\Users\fmwebroot> c:\test.ps1
name version
---- -------
Microsoft Visual C++ 2008 Redistributable - x64... 9.0.21022
Microsoft Visual C++ 2010 x64 Redistributable ... 10.0.40219
Microsoft Visual C++ 2010 x86 Redistributable ... 10.0.40219
aws-cfn-bootstrap 1.4.5
EC2ConfigService 3.5.228.0
AWS Tools for Windows 3.7.543.0
Microsoft Web Deploy 3.5 3.1237.1764
IIS Advanced Logging 1.0 1.0.0625.10
Microsoft Web Platform Installer 5.0 5.0.50430.0
Mercurial 3.1.1 (x64) 3.1.1
ConEmu 140814.x64 11.140.8140
Microsoft Visual C++ 2008 Redistributable - x86... 9.0.21022
Opsview NSClient++ Windows Agent (x64) 0.3.9.336
New Relic Server Monitor 3.3.2.0
7-Zip 9.20 (x64 edition) 9.20.00.0
New Relic .NET Agent (64-bit) 3.10.43.0
Python 3.4.1 (64-bit) 3.4.1150
以系统用户身份运行时,始终缺少Python包的名称。我在多台机器上看到了这个。操作系统是Windows Server 2012 R2。
PS C:\Users\fmwebroot> psexec -s cmd /c "echo . | powershell -File c:\test.ps1"
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
name version
---- -------
Microsoft Visual C++ 2008 Redistribu... 9.0.21022
Microsoft Visual C++ 2010 x64 Redis... 10.0.40219
Microsoft Visual C++ 2010 x86 Redis... 10.0.40219
aws-cfn-bootstrap 1.4.5
EC2ConfigService 3.5.228.0
AWS Tools for Windows 3.7.543.0
Microsoft Web Deploy 3.5 3.1237.1764
IIS Advanced Logging 1.0 1.0.0625.10
Microsoft Web Platform Installer 5.0 5.0.50430.0
Mercurial 3.1.1 (x64) 3.1.1
ConEmu 140814.x64 11.140.8140
Microsoft Visual C++ 2008 Redistribu... 9.0.21022
Opsview NSClient++ Windows Agent (x64) 0.3.9.336
New Relic Server Monitor 3.3.2.0
7-Zip 9.20 (x64 edition) 9.20.00.0
New Relic .NET Agent (64-bit) 3.10.43.0
3.4.1150
cmd exited on IP-0A63009C with error code 0.
PS C:\Users\fmwebroot>
我注意到了这个问题,因为这个Powershell代码是由正在运行的进程生成的,用于列出已安装的软件,我无法解释为什么它一直认为没有安装Python。我设法通过分析实际发生的事情来创建这个问题的简单演示。
有谁能告诉我这里发生了什么,以及我如何解决它?