Page 1 of 2

not getting output from msgbox

Posted: Mon Jul 15, 2019 8:22 am
by ocsscott6969
PSS 019 current build. win 10 64bit

code works in PSS but once compiled I am not getting the message boxes not am I getting the correct path of the exe that is running

Ive tried compiling as windows form and application neither seems to work. (which is the better option for a windows form and msgboxes?

any ideas on both the pth not showing once compiled and some message boxes not happening?

Param (
[string]$p1
)

function Show-MsgBox
{

[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory = $true)]
[string]$Prompt,
[Parameter(Position = 1, Mandatory = $false)]
[string]$Title = "",
[Parameter(Position = 2, Mandatory = $false)]
[ValidateSet("Information", "Question", "Critical", "Exclamation")]
[string]$Icon = "Information",
[Parameter(Position = 3, Mandatory = $false)]
[ValidateSet("OKOnly", "OKCancel", "AbortRetryIgnore", "YesNoCancel", "YesNo", "RetryCancel")]
[string]$BoxType = "OkOnly",
[Parameter(Position = 4, Mandatory = $false)]
[ValidateSet(1, 2, 3)]
[int]$DefaultButton = 1
)
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic") | Out-Null
switch ($Icon)
{
"Question" { $vb_icon = [microsoft.visualbasic.msgboxstyle]::Question }
"Critical" { $vb_icon = [microsoft.visualbasic.msgboxstyle]::Critical }
"Exclamation" { $vb_icon = [microsoft.visualbasic.msgboxstyle]::Exclamation }
"Information" { $vb_icon = [microsoft.visualbasic.msgboxstyle]::Information }
}
switch ($BoxType)
{
"OKOnly" { $vb_box = [microsoft.visualbasic.msgboxstyle]::OKOnly }
"OKCancel" { $vb_box = [microsoft.visualbasic.msgboxstyle]::OkCancel }
"AbortRetryIgnore" { $vb_box = [microsoft.visualbasic.msgboxstyle]::AbortRetryIgnore }
"YesNoCancel" { $vb_box = [microsoft.visualbasic.msgboxstyle]::YesNoCancel }
"YesNo" { $vb_box = [microsoft.visualbasic.msgboxstyle]::YesNo }
"RetryCancel" { $vb_box = [microsoft.visualbasic.msgboxstyle]::RetryCancel }
}
switch ($Defaultbutton)
{
1 { $vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton1 }
2 { $vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton2 }
3 { $vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton3 }
}
$popuptype = $vb_icon -bor $vb_box -bor $vb_defaultbutton
$ans = [Microsoft.VisualBasic.Interaction]::MsgBox($prompt, $popuptype, $title)
return $ans
} #end function

Show-MsgBox -Title "test1" -Prompt "test1" -Icon Critical -BoxType OKOnly
$A = $PSScriptRoot
$global:LocalPath = $A
Show-MsgBox -Title "test2" -Prompt "$A" -Icon Critical -BoxType OKOnly
Show-MsgBox -Title "localPath" -Prompt "$global:LocalPath" -Icon Critical -BoxType OKOnly

$B = $PSCommandPath
$global:LocalPath2 = $B
Show-MsgBox -title "localPath" -Icon Critical -BoxType OKOnly -Prompt "$global:LocalPath2"

$form_main_Load={
#TODO: Initialize Form Controls here

#$global:Debug = $true

$PSV = $psversiontable.psversion.tostring()

#$PSV = "3.2"

$RemoteVer = "0.0.0"
$AppVer = "2.3.0"

$RemoteVer = get-content "\\xxx\AppInstallerVerCheck\version.txt"

If ($PSV -lt 5.0)
{
Show-MsgBox -title "Error - PowerShell Version 5 Required!!" -Icon Critical -BoxType OKOnly -Prompt "Please Install Powershell 5 From the Powershell Folder on the thumbdrive. `n `nREBOOT and then run App Installer again!"

$form_main.close()
return
}

$A = $PSScriptRoot
$global:LocalPath = $A
Show-MsgBox -title "localPath" -Icon Critical -BoxType OKOnly -Prompt "$global:LocalPath"

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build:
32 or 64 bit version of product:
Operating system:
32 or 64 bit OS:

*** Please add details and screenshots as needed below. ***

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

Re: not getting output from msgbox

Posted: Mon Jul 15, 2019 11:20 am
by Alexander Riedel
*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build:
32 or 64 bit version of product:
Operating system:
32 or 64 bit OS:

Re: not getting output from msgbox

Posted: Mon Jul 15, 2019 11:29 am
by ocsscott6969
5.6.165 64 bit on win 10 64bit

Re: not getting output from msgbox

Posted: Mon Jul 15, 2019 12:57 pm
by brittneyr
When you run the build and run your exe, is there any output in the Tools Output window?
SPS_ToolsOutputw.png
SPS_ToolsOutputw.png (132.41 KiB) Viewed 4444 times

Re: not getting output from msgbox

Posted: Mon Jul 15, 2019 1:02 pm
by ocsscott6969
no errors see below.

should I be compiling as windows, windows forms or windows applications I am having a hard time understanding the difference

> Package 'P:\!!PowerShell_GUI_Projects\AppInstaller2.3\AppInstallerMain.psf'
>> Building (AppInstallerMain.psf) ...
SAPIEN Package and Deploy Tool 4.1 (c) 2005 - 2019 SAPIEN Technologies, Inc.

------ Build started: AI2, Configuration: x86 ------
Packaging with SAPIEN PowerShell V5 Host (Windows) Win32
Adding P:\!!PowerShell_GUI_Projects\AppInstaller2.3\AppInstallerMain.Package.ps1
Writing scripts to bin\x86\AI2.exe
Embedding default manifest...
Package completed


>> Completed

Re: not getting output from msgbox

Posted: Mon Jul 15, 2019 1:27 pm
by Alexander Riedel
It really depends on what you are doing.

In a nutshell:

Windows is a generic Windows app and all output (e.g. Write-Host) is directed to a message box.
Windows Forms eats all generic powershell output from Write-host, write-output, out-* etc. All output must be through form elements or message boxes.
Windows Application creates a window where all console output is piped to a windows text box.

Re: not getting output from msgbox

Posted: Mon Jul 15, 2019 1:32 pm
by ocsscott6969
all my output is on the windows form itself or via the show-messagebox code I attached. what is best for that scenario?

but for my original questions any idea why the message boxes are not showing up compiled but work perfect inside pss?

and the same for the path issue it always shows in PSS but not working compiled?

any chance I could call/contact someone directly.. a 5 min screen share would probably solve the whole thing ;)

Re: not getting output from msgbox

Posted: Mon Jul 15, 2019 3:17 pm
by brittneyr
If all of your output is in a form or message boxes, you should use a Windows Form Engine.
With the code you have provided, I have it running and showing the messages just fine when packaged with Window Forms V5 engine:
SPS-packager.png
SPS-packager.png (58.53 KiB) Viewed 4396 times
If you run the directly from its folder, does it still not work?
Regarding the path issue, there was a known issue in the packager with $PSScriptRoot. Please try the latest build (5.6.166) of PowerShell Studio.
We do not provide Call support.

Re: not getting output from msgbox

Posted: Tue Jul 16, 2019 6:42 am
by ocsscott6969
The MSGbox was a issue when the path was black it failed that's why I didn't get all of them. I am compiling as windows forms

I Upgraded to .166 but still get the Issue. In the debugger all my path varialbes are correct when running the compiled exe they are blank. code and screenshots below

1)
$A = $PSScriptRoot
$global:LocalPath = $A
Show-MsgBox -Title "test2" -Prompt "* $A" -Icon Critical -BoxType OKOnly

2)
$B = $PSCommandPath
$global:LocalPath2 = $B
Show-MsgBox -title "cmdPath" -Icon Critical -BoxType OKOnly -Prompt "* $global:LocalPath2"

3)
$C = Get-Location
$global:getLocalPath = $C.path.ToString()
Show-MsgBox -title "getlocalPath" -Icon Critical -BoxType OKOnly -Prompt "* $global:getLocalPath"

see word doc for test result but basically I don't get data from $PSScriptRoot and $PSCommandPath from the compiled exe but its perfect in the debugger

$C = Get-Location
$global:getLocalPath = $C.path.ToString()

works the same in both but I get Microsoft.powershell.core.filesystem: appended to the beginning of the path

Thanks
TestResults.JPG
TestResults.JPG (40.72 KiB) Viewed 4315 times

Re: not getting output from msgbox

Posted: Tue Jul 16, 2019 9:36 am
by brittneyr
So far I have been able to reproduce the issue you are having with 'Microsoft.PowerShell.Core' being appended to the beginning of the path, but I'm able to get values from $PSScriptRoot and $PSCommandPath. We are currently look into this issue and will update you when we have more information. If there is any other details you can provide to help us recreate your issue?
Also, is this the complete script you are running?