2017-02-07 100 views
0

我试图做一个非常简单的代码来检测笔记本电脑架构。以下是代码。我的笔记本电脑是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 
} 

回答

1

你的消息框在变量声明本身的运行时间,你可以通过运行$x = [System.Windows.Forms.MessageBox]::Show("This is a 64 bit version" , "Status")声明证实了这一only.show方法显示消息框,并存储信息(在这种情况下,“OK”)响应在变量中,试试这个:

#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") 
}