我试图用一个非常简单的代码来检测笔记本电脑架构。下面是代码。我的笔记本电脑是64位,但它也会显示32位消息框。代码还有什么遗漏吗?
#Load assembly
add-type -assemblyname system.windows.forms
#Assign messagebox to variable
$message1 = [System.Windows.Forms.MessageBox]::Show("This is a 64 bit version" , "Status")
$message2 = [System.Windows.Forms.MessageBox]::Show("This is a 32 bit version" , "Status")
#Display message based on the architecture
if ([System.Environment]::Is64BitProcess) {
echo $message1
} else {
echo $message2
}
答案 0 :(得分:1)
您的消息框在变量声明本身时运行,您可以通过仅运行$x = [System.Windows.Forms.MessageBox]::Show("This is a 64 bit version" , "Status")
语句来确认。显示消息框并存储消息的响应(" ok&#34 ;在这种情况下)在变量中,试试这个:
#Load assembly
add-type -assemblyname system.windows.forms
#Display message based on the architecture
if ([System.Environment]::Is64BitProcess) {
[System.Windows.Forms.MessageBox]::Show("This is a 64 bit version" , "Status")
} else {
[System.Windows.Forms.MessageBox]::Show("This is a 32 bit version" , "Status")
}