Abhinay
Posts: 36
Joined: Wed Feb 27, 2019 9:33 am

How to display the runtime message

How to display the runtime message on the message box of the installer.

Code: Select all

PS D:\RSP Firmware Update\RSP_Firmware> $a = .\SinetProg.exe /i /a:192.168.29.20
PS D:\RSP Firmware Update\RSP_Firmware> Write-output "Your Current " $a[0] "and your current " $a[4]
Your Current
Device Type: SP650
and your current
Firmware Version: 1.1.73
Instead of Write-output i want it to be displayed on message box of the installer how to do that
I tried the code as below but it did not work, Can you help me with this

Code: Select all

 [System.Windows.MessageBox]::Show("Your Current " $a[0] "and your current " $a[4])
Abhinay
Posts: 36
Joined: Wed Feb 27, 2019 9:33 am

Re: How to display the runtime message

I have tried the code, but it does not work

Code: Select all

# Block for declaring the script parameters.
Param()
   # Your code goes here.
Add-Type -AssemblyName PresentationFramework

cd "C:\Program Files\Weir Minerals\RSP Firmware\RSP Firmware\"

$rspIps = "192.168.29.20","192.168.29.21","192.168.29.22","192.168.29.23","192.168.29.24","192.168.29.25","192.168.29.26","192.168.29.27"

foreach ($rspIp in $rspIps)
{
   
   if (Test-Connection $rspIp -Count 1 -ea 0 -Quiet)
   {

     if((($rspIp.Substring(11,2)) % 2) -eq 0)
     {

	$a = .\SinetProg.exe /i /a:$rspIp
   Write-output "Your Current " $a[0] "and your current " $a[4]
        [System.Windows.MessageBox]::Show("Your Current " $a[0] "and your current " $a[4])
       
     }
     if((($rspIp.Substring(11,2)) % 2) -ne 0)
     {
     

	$b = .\SinetProg.exe /i /a:$rspIp
Write-output "Your Current " $b[0] "and your current " $b[4]
        [System.Windows.MessageBox]::Show("Your Current " $b[0] "and your current " $b[4])
	
    }
	
   }
   else
   {
       [System.Windows.MessageBox]::Show($rspIp could not be pinged)
   }
}
You can give me suggestions like if it can be displayed on message box or somewhere else
Catalin
Posts: 6592
Joined: Wed Jun 13, 2018 7:49 am

Re: How to display the runtime message

Hello Abhinay,

The message displayed by the Show() method must be included in " (quotes) if it contains any text beside your variables. Additionally, variables that are included in double quotes will expand their values at runtime. That means that you should not escape them in the Show() method. Here is a little example so you can better understand what I mean here:

Code: Select all

Add-Type -AssemblyName PresentationFramework
$var1 = "there"
$var2 = "how are you?"
[System.Windows.MessageBox]::Show("Hello $var1 $var2")
The output of the above code will be:

Code: Select all

Hello there how are you?
However, if we use single quotes instead of the double quotes (e.g. 'Hello $var1 $var2'), the output will be:

Code: Select all

Hello $var1 $var2
Hope things are a bit more clear now.

With that being said, the input of your Show() method should be:

Code: Select all

[System.Windows.MessageBox]::Show("Your Current $a[0] and your current $a[4]")
respectively:

Code: Select all

[System.Windows.MessageBox]::Show("Your Current $b[0] and your current $b[4]")
Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Abhinay
Posts: 36
Joined: Wed Feb 27, 2019 9:33 am

Re: How to display the runtime message

It worked... Thank you
Catalin
Posts: 6592
Joined: Wed Jun 13, 2018 7:49 am

Re: How to display the runtime message

You are always welcome, Abhinay.

I am glad it worked.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”