- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了以下脚本来检查应用程序名称并回显某些属性(如果已安装):
$input = "Microsoft Office Professional"
$appName = "*" + $input + "*"
$responseX64 = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.DisplayName -like $appName} | Select-Object @{Expression={$_.DisplayName + "|" + $_.DisplayVersion +"|x64"}} | Sort-Object -Unique | ft -HideTableHeaders
$responseX86 = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.DisplayName -like $appName} | Select-Object @{Expression={$_.DisplayName + "|" + $_.DisplayVersion +"|x86"}} | Sort-Object -Unique | ft -HideTableHeaders
If (([string]::IsNullOrEmpty($responseX64)) -and ([string]::IsNullOrEmpty($responseX86)))
{
Write-Output "No matches found."
exit
}
else
{
Write-Output $responseX64
Write-Output $responseX86
}
为了完整性,我检查了 x86 和 x64 卸载注册表项。当我在 x64 PowerShell session 中运行它时,它按预期工作,并正确返回我安装了单个 x86 Microsoft Office:
Microsoft Office Professional Plus 2016|16.0.4266.1001|x86
但是,当我在同一台计算机上的 PowerShell x86 session 中运行它时(因为它将由我的 x86 管理代理运行),我得到以下返回:
Microsoft Office Professional Plus 2016|16.0.4266.1001|x64
Microsoft Office Professional Plus 2016|16.0.4266.1001|x86
我仔细检查了 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall 下的注册表项,以确保其中没有 Office 的某些 x64 工件,但实际上什么也没有。如何修改此脚本,以便在 x86 上下文中运行时返回准确的结果?
最佳答案
您的问题是,对于 32 位进程,以下关键路径引用相同位置,即 32 位应用程序的注册 TableView :
# To both 64- and 32-bit processes: The registry view for 32-bit applications.
HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
# To 32-bit processes: same as above
# To 64-bit processes: the 64-bit view of the registry.
HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*
换句话说:您的代码在 32 位进程中运行时,会执行两次相同的操作。
仅使用注册表 key 路径将不允许 32 位进程查看 64 位注册表。
但是,有解决方法:
通过目录 $env:WinDir\SysNative
将 PowerShell 的 64 位实例作为外部进程调用 - 参见下文。
直接使用.NET类型,如this answer所示.
调用标准reg.exe
实用程序,它具有 /reg:32
和 /reg:64
参数,用于针对特定位的配置单元。但是,使用这种方法您将失去 PowerShell 丰富的数据类型支持,并且您必须将结果解析为文本。
使用脚本 block 从(32 位)PowerShell 调用 64 位 PowerShell { ... }
自动以 CLIXML 格式序列化 64 位实例的输出对象,这使得调用实例自动以合理的保真度反序列化它们[1],以便您的原始过滤命令应该起作用:
# Works only in a 32-bit process.
& $env:WINDIR\SysNative\WindowsPowerShell\v1.0\powershell.exe {
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*
} |
Where-Object {$_.DisplayName -like $appName} |
Select-Object @{Expression={$_.DisplayName + "|" + $_.DisplayVersion +"|x64"}} |
Sort-Object -Unique
要确定您的脚本是否在 32 位进程中运行,请使用以下命令:
# PowerShell v3 and above.
$is32Bit = [Environment]::Is64BitProcess
# PowerShell version 2 alternative
$is32Bit = ${env:ProgramFiles(x86)} -eq ${env:ProgramFiles} -or
-not ${env:ProgramFiles(x86)}
-or -not ${env:ProgramFiles(x86)}
部分检测运行的情况在纯 32 位 Windows 版本上,但请注意,显然,那里不存在 64 位定义。
在 PowerShell v3 及更高版本中,您可以使用 [Environment]::Is64BitOperatingSystem
轻松测试操作系统(Windows 安装)是否为 64 位
Theo's helpful answer提供一个辅助函数,以向后兼容的方式确定进程和操作系统位数。
[1] 除了一些众所周知的类型之外,输入对象被反序列化为 [PSCustomObject]
实例,其静态属性反射(reflect)原始对象的属性值 - 请参阅 this answer了解详情。
关于在 x86 上下文中运行时,PowerShell 返回已安装软件的不准确结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53687112/
当然,您可以将剩余文件大小除以当前下载速度,但如果您的下载速度波动(而且它会波动),这不会产生很好的结果。有什么更好的算法可以产生更平滑的倒计时? 最佳答案 安exponential moving a
对于一个业余项目,我正在尝试对齐照片并创建 3D 图片。我基本上在一个钻机上有 2 个相机,我用来拍照。我会自动尝试以您获得 3D SBS 图像的方式对齐图像。 它们是高分辨率图像,这意味着需要处理大
当然,您可以将剩余的文件大小除以当前的下载速度,但如果您的下载速度波动(而且会波动),这不会产生很好的结果。什么是产生更平滑倒计时的更好算法? 最佳答案 安exponential moving ave
我有一个数据集,其中包含患有糖尿病和未患有糖尿病的人。我想使用这些数据训练一个模型来计算糖尿病状况未知的人的风险概率。我知道在培训中没有被诊断出糖尿病的人大多数都没有糖尿病,但很可能其中一些人可能患有
let parent = path[row-1] let child = path[row] let indexOfChild = matrix[parent.obje
我正在编写一些使用 Element.getBoundingClientRect 的代码(gBCR),加上内联样式更新,以执行计算。 这不适用于一般网站,我不关心或不感兴趣是否有“更好的 CSS 方式”
我有一个很大的 csv 文件,其中包含大量脏数据,我想通过消除所有不是绝对必要的值来稍微清理一下它。 Here是我正在谈论的文件。 它有以下组件: 网站,标题,开始日期,开始日期,雇主,地点,纬度,
有谁知道一个库,它为 Java 提供了一个错误不高于 1-2 毫秒的 Thread.sleep()? 我尝试了 sleep 、错误测量和 BusyWait 的混合,但在不同的 Windows 机器上我
UiApp有DateBox和 DateTimeFormat 对于那个类(class)。但是,不存在诸如 TimePicker 或 TimeBox 这样的东西,用户可以通过明确指定的方式(例如通过使用
因此,我使用 sklearn 的 svm.SVC 模块编写了一个程序来学习 mnist 数据集,出于某种原因,每当我计算其准确性为 100% 时。这似乎好得令人难以置信,这是预期的吗? from sk
我当前找到了 gpytorch ( https://github.com/cornellius-gp/gpytorch )。它似乎是将 GPR 集成到 pytorch 中的一个很棒的包。第一次测试也呈
我正在使用 QT Creator 5.9 创建一个简单的 Web 浏览器模型,我的 EditLine/Text Box 有问题: 1.如何在转到不同的网站/页面后自动更新显示的 URL 字符串。 2。
我在 Linux 上尝试 time -p 命令,我写了一些代码来浪费 CPU 周期: #include using namespace std; int main() { long int c;
亲爱的程序员/脚本编写者/工程师/其他人, 问题:我目前正在为 Android 3.2 平板电脑开发增强现实应用程序,但在获取准确的罗盘读数方面遇到一些问题。我需要确切地知道平板电脑所面向的 (z)
我最近一直在尝试了解 Apache Spark 作为 Scikit Learn 的替代品,但在我看来,即使在简单的情况下,Scikit 收敛到准确模型的速度也远远快于 Spark。例如,我使用以下脚本
如果不是,它的准确性如何? 我想在下载之前知道图片的大小。 最佳答案 HTTP Content-length header 是否格式错误?是的。 您是否应该相信它能公平地表示消息正文的大小?是的。 关
这是一个关于 ngram 线性回归的问题,使用 Tf-IDF(术语频率 - 逆文档频率)。为此,我使用 numpy 稀疏矩阵和 sklearn 进行线性回归。 使用一元语法时,我有 53 个案例和 6
对于某些给定的固定宽度,如何计算特定标签 (NSTextField) 中字符串的高度? 我用谷歌搜索了各种方法并尝试了 this method from Apple .它的工作原理,除了高度变成一行对
我是一名优秀的程序员,十分优秀!