2017-02-07 132 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") 
}