Johan
Johan

Reputation: 307

To detect system architecture

Im trying to do a very simple code to detect the laptop architecture. Below is the code. My laptop is 64 bit but it will also display 32 bit message box. Is there anything else im missing to code?

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

Upvotes: 0

Views: 106

Answers (1)

ClumsyPuffin
ClumsyPuffin

Reputation: 4069

your message boxes are running at the time of variable declaration itself,you can confirm this by running $x = [System.Windows.Forms.MessageBox]::Show("This is a 64 bit version" , "Status") statement only.show method shows the message box and stores the response of message ("ok" in this case) in the variable , try this :

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

Upvotes: 1

Related Questions