Script Packager

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
markcusano
Posts: 21
Last visit: Mon Oct 23, 2017 1:22 pm

Script Packager

Post by markcusano »

Hello all,
I'm trying to create a simple Powerhell Studio Windows Forms app. Simply click a button and it gets the last boot time of a server that's hardcoded in the script. The app doesn't return results from my desktop, however if I copy the exe file to a server, it works great. I've tried every platform combination and none of them work from my desktop. Does anyone have an idea how to get the exe to work from your desktop? I should also say that if I just create a hello world app, it works from my desktop. It just seems like I can't get any results from a server when I run it from my desktop.

Thanks in advance.

Mark
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: Script Packager

Post by DevinL »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
DevinL
SAPIEN Technologies, Inc.
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: Script Packager

Post by DevinL »

If you could provide the psf for the form that you've created, that would greatly help us in determining what's going on.

With what you're saying, it could be a wide number of things.
DevinL
SAPIEN Technologies, Inc.
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: Script Packager

Post by DevinL »

Also, can you provide the psbuild that is alongside it? This is to determine exactly which packager options you have set and if any of them may be causing you trouble.
DevinL
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Script Packager

Post by Alexander Riedel »

Additionally, please provide information about your 'desktop'. Please remember that we cannot see your screen. We need to know what OS, bitness, Powershell version etc you have.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
markcusano
Posts: 21
Last visit: Mon Oct 23, 2017 1:22 pm

Re: Script Packager

Post by markcusano »

Thanks for the reply! Just want to make sure I say that I can run the ps1 code in the ise and it runs the gui and it works. However, I want to just be able to give users the exe without the code.

My desktop
Powershell version is 3
Windows 7 ENT 64bit OS

The test server I'm trying to hit
Powershell version is 2
Windows Server 2008r2 64bit OS

I've tried every combination in deployment options, but currently have:

PACKAGER:
Powershell V2 Host (Windows Forms) x64
STA mode enabled
Generate .config file is enabled
Run mode = Current User
Manifest Creation = Enable A Default Manifest
Execution Restrictions = No changes to this tab. No restrictions.
No build options

INSTALLER:
Product Type = Windows Application
MSI Options:
64bit installer disabled
Install for all users enabled
Require Administrator disabled
Minimum powershell version required = None




























Here is the basic .psf code



###########################################################################################################


$form1_Load={
#TODO: Initialize Form Controls here
#$formMain.AcceptButton = $buttonLoad
}

$buttonExit_Click={
#TODO: Place custom script here
$form1.Close()
}

$buttonLoad_Click= {
Load-Text
#$richtextbox1.Text = 'hello world'
[string]$bootresults = Get-WmiObject win32_operatingsystem -ComputerName 'hardcodedservernamehere' | select @{ Expression = { $_.csname }; Label = "Server Name" }, @{ LABEL = 'Last Boot Up Time'; EXPRESSION = { $_.ConverttoDateTime($_.lastbootuptime) } }
#$bootresults = Get-WmiObject win32_operatingsystem | select @{ Expression = { $_.csname }; Label = "Server Name" }, @{ LABEL = 'Last Boot Up Time'; EXPRESSION = { $_.ConverttoDateTime($_.lastbootuptime) } }
$richtextbox1.Text = 'here are the results ' + $bootresults

#$richtextbox1.Text = 'hello world'
#$richtextbox1.Text = $ServerRebootInfo



}

$buttonCopy_Click={
#The following requires STA mode
# if($textbox1.Text.Length -gt 0)
# {
# [System.Windows.Forms.Clipboard]::SetText($textbox1.Text)
# }
#Alternative - Does not require STA
$richtextbox1.SelectAll() #Select all the text
$richtextbox1.Copy() #Copy selected text to clipboard
$richtextbox1.Select(0,0); #Unselect all the text
}

#################################################
# Customize LoadText Function
#################################################

function Load-Text
{
# -------------------------
# Sample Code to Load Text
# -------------------------
# $richtextbox1.Text = Get-Process | Out-String
}









##########################################################################################










Here is the psbuild:





[Package]
Output=helloworldnew
IconFile=C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2016\ScriptPackage.ico
Manifest=
ManifestType=1
STA=1
GenerateConfigFile=1
Password2=
Username=
Engine=SAPIEN PowerShell V2 Host (Windows Forms) x64
UseRunAs=0
PFX=
TimeStamp=http://timestamp.globalsign.com/scripts/timstamp.dll
PFXPassword2=
RestrictUser=
RestrictMAC=
RestrictMachine=
RestrictDomain=
RestrictInstance=1
RestrictedOS=
FileVersion=1.0.0.1
ProductVersion=1.0.0.1
ProductName=helloworldnew
Description=
Company=PNC
Copyright=Copyright (c) 2017 All rights reserved
InternalName=
OriginalName=helloworldnew
Comments=
AutoIncrementVersion=0
[MSI]
ProductGUID=
UpgradeGUID=
ProductName=helloworldnew
ProductVersion=1.0.0.1
ProductType=Windows Application
CompanyName=PNC
ProductIcon=C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2016\MSIBuilder\Windows_Application_Installer.ico
LastVersion=1.0.0.1
ShortcutFile=(Packaged Executable)
MSIName=helloworldnew
OutputFolder=XXX:\MyPowershellScripts\Powershell_Projects\HelloWorldNewTest
StagingFolder=
64BitInstall=0
MinimumPowershellVersion=None
AllUsers=1
AsAdmin=0
Certificate=
Password=
TimeStampURL=http://timestamp.globalsign.com/scripts/timstamp.dll
UseSigningWizard=0
[MSI Files]
File1=(Packaged Executable)
[Deploy]
MainFile=(Packaged Executable)
Destination=XXX:\MyPowershellScripts\Powershell_Projects\HelloWorldTest
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Script Packager

Post by jvierra »

Start with this PSF and test again.
Attachments
Test-BadRTF.psf
(17.71 KiB) Downloaded 135 times
User avatar
markcusano
Posts: 21
Last visit: Mon Oct 23, 2017 1:22 pm

Re: Script Packager

Post by markcusano »

I have SAPIEN PS 2016, but this file will not open for me.

Here is the error I'm getting
Test-BadRTF.psf: Unable to load Test-BadRTF.psf (File Format: v2.1), because it was created with a different version of SAPIEN PowerShell Studio 2016.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Script Packager

Post by jvierra »

Try this version:
Attachments
Test-BadRTFv2.psf
(4.11 KiB) Downloaded 138 times
User avatar
markcusano
Posts: 21
Last visit: Mon Oct 23, 2017 1:22 pm

Re: Script Packager

Post by markcusano »

Thank you.

I was able to get the last one to run. It runs fine from my desktop when getting my desktop lastreboot time. However, same as before, when I try to change the computername to check a server reboot time, it returns nothing except the text that I put there to validate that it's getting to that step, which is.... 'here are the results '
This topic is 6 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked