Details on Start sequence and use of Startup.pss and globals.ps1

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

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 1 year and 1 month 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.
User avatar
shiroscout
Posts: 41
Last visit: Sat Jul 15, 2023 7:13 pm

Details on Start sequence and use of Startup.pss and globals.ps1

Post by shiroscout »

Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.164
OS: Windows 10 Pro (64 Bit)
Build: v10.0.19045.0

Hello,

Currently, I only use PowerShell 5, STA Mode, focusing on the 64bit Windows Form app.
I run and launch in Elevated Mode.
I've uninstalled all modules used in app and commented out modules.
The app should run from the 3 files, and use/get some of the files in the other folders when required.

I am a novice but am going through all info center training, looking online for WinForm and .Net, and learning PowerShell as an effort.
I have the 3 files below and have some folders with other files or tools.
In PowerShell Studio my app seems to work as expected, but any way packaged ( I prefer MSI) I have buttons or items that do not work.
I also am having the packaged files all dumped into 1 folder, but I need the folder structure intact.

But if we can we focus on the intended use or the 3 files because I think that is where I am making my largest current mistake.
From reading several posts on the Sapien site, it seemed as though my issue may be related to me putting code in the wrong files, and the execution sequence is not able to load everything correctly.
I have tried to read all articles and posts I could find but can you please help me understand the way that the 3 main files work and their intended usage:
Startup.pss (Currently nothing added to basic FormLoad code)
Globals.ps1 ( Functions in here, Variables in here but currently I have commented out almost everything possible and put only what is needed in the
MainForm.psf
( What Windows Forms elements are supposed to be dedicated in each)

I do not know what else may help you help me.
If you want specific code or screenshots let me know and I will post it, and know for future use next time as well.

Thank You,

Wayne
Thank You,

Wayne
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 1:00 pm
Answers: 39
Been upvoted: 30 times

Re: Details on Start sequence and use of Startup.pss and globals.ps1

Post by brittneyr »

The script that is generated when you run in PowerShell Studio vs when you are packaging is the same other than the name. For packaging, the script generated is name ProjectName.package.ps1. When running, it is named ProjectName.Run.ps1.

I'm not sure what your buttons that are not working are suppose to do, but if they are require administrator privileges, make sure you are giving your executable administrator privileges.

As for your file structure, are you adding the files/folders to create the file structure you need in the Files and Folders section?

When building a project, the Startup.pss, Global.ps1, and MainForm.ps1 will be combined into one script.
Globals.ps1 is the file to put code you want to reference from other files in your project.
Startup.pss is the file that calls your MainForm to start the project. Generally, anything you need initialized before the start of the form would go in this file.
MainForm.psf is where all your controls for you form should be. All form code is wrapped in a function (called a reference function). This is the function that is called in Startup.pss. This function is generally named like the following:
  1. Show-MainForm_psf
I recommend reading the following articles for more information:
https://www.sapien.com/blog/2022/03/15/ ... roduction/
https://www.sapien.com/blog/2022/08/03/ ... -projects/
https://www.sapien.com/blog/2022/01/04/ ... ll-studio/
Brittney
SAPIEN Technologies, Inc.
User avatar
shiroscout
Posts: 41
Last visit: Sat Jul 15, 2023 7:13 pm

Re: Details on Start sequence and use of Startup.pss and globals.ps1

Post by shiroscout »

I had hoped for a clearer answer but if it is simply my lack of knowledge, then I will do my research. I'm sure your not intentionally trying to withold any free info or knowledge you might be able to share.

I do have all the URLS you gave me, as well as I found the online manual here:
https://info.sapien.com/manuals/powersh ... index.html
Very informative for us new users.

I do not come from a coder, web developer, programmer type background, so the whole product PowerShell Studio, plus
Sapien products are specialized products. I know that they deeply intertwine with .Net, PowerShell, etc... but I am trying to get a grasp and understanding of the foundational concepts of the use of it, as well as what languages, etc... it can use.

Can you at least answer about this...
If I want to learn powershell studio what other knowledge will I need to learn? I believe, obviosly PowerShell, and I think WinForms usage, .Net, C#
Would that for starters cover what is suggested and needed to learn?
Currently, I am only focusing on PowerShell Studio Features and usage, PowerShell 5x Documentation, and some WinForms usage when needed.

Thank You,

Wayne
Thank You,

Wayne
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Details on Start sequence and use of Startup.pss and globals.ps1

Post by Alexander Riedel »

As you stated, knowing PowerShell is obviously key. PowerShell itself is deeply rooted in .NET and so is WinForms.
I would strongly recommend to take a beginner's class in C#. May it be online video, book or in person, it will enable you to read and understand concepts.
Many tips and tricks and samples revolving around WinForms, accessing system parts that are not readily available in PowerShell, older Windows APIs etc are very often available in C#.
So being able to read and understand this is very helpful. You don't need to be able to craft the next big life changing application in it, but being able to read it will help you tremendously.
Additionally some activities can be done in C# even inside a PowerShell application or script.
The good news is, once you understand the fundamentals of a 'traditional' programming language like C#, other languages will become far easier to read and comprehend.
Languages are (mostly) more similar than different.

Hope this helps.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Details on Start sequence and use of Startup.pss and globals.ps1

Post by Alexander Riedel »

Here is an example I found on twitter recently that illustrates this:

#PowerShell tip: if you're using `Get-Content` to simply read a file, it's much faster to use [http://System.IO.File]::ReadAllBytes() or [http://System.IO.File]::ReadAllText() even in a pipeline. About 95% faster! `Get-Content` is useful if you want objs per line.

Credit: https://twitter.com/Steve_MSFT/status/1 ... ylKLg8JoPw
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 1 year and 1 month 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.