Help with GUI

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 8 years 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.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Help with GUI

Post by jvierra »

dan.potter wrote:For display purposes as his first screenshot :)
His question is how to use a checkedlistbox to do what he did manually without PowerShell Studio.
What does the display have to do with objects in a checked listbox?
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Help with GUI

Post by dan.potter »

It seemed he wanted to select the items in his screenshot and install that particular program.

The switch would associate the name selected to an executable, or script.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Help with GUI

Post by dan.potter »

"Each item in the CheckedListBox corresponds to a program I want to install"

then he has start-process scriptpath.vbe.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Help with GUI

Post by jvierra »

dan.potter wrote:"Each item in the CheckedListBox corresponds to a program I want to install"

then he has start-process scriptpath.vbe.
Yes. So how does that sto him from storing the installer name into the listbox?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Help with GUI

Post by jvierra »

It doesn't matter. Whatever you need get set in the listbox. Listboxes store objects not strings. We just add everything in

$objs+=[pscustomobject]@[Name='Adobe';Installer='c:\installfiles\adobe\setup.msi';Aruments='/qn /ALL'
...
$listbox.Datasource=[arraylist]$objs
$listbox.DisplayMember='Name'

Now everything is in the listbox or checkd listbox.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Help with GUI

Post by jvierra »

It doesn't matter. Whatever you need get set in the listbox. Listboxes store objects not strings. We just add everything in

$objs+=[pscustomobject]@[Name='Adobe';Installer='c:\installfiles\adobe\setup.msi';Aruments='/qn /ALL'
$objs+= ...
$objs+= ....
...
$listbox.Datasource=[arraylist]$objs
$listbox.DisplayMember='Name'

Now everything is in the listbox or checkd listbox.
We can even load it from a CSV file.
User avatar
WSUsoftware
Posts: 30
Last visit: Thu Feb 17, 2022 2:52 pm

Re: Help with GUI

Post by WSUsoftware »

jvierra wrote:It doesn't matter. Whatever you need get set in the listbox. Listboxes store objects not strings. We just add everything in

$objs+=[pscustomobject]@[Name='Adobe';Installer='c:\installfiles\adobe\setup.msi';Aruments='/qn /ALL'
$objs+= ...
$objs+= ....
...
$listbox.Datasource=[arraylist]$objs
$listbox.DisplayMember='Name'

Now everything is in the listbox or checkd listbox.
We can even load it from a CSV file.
I guess I will preface my response by saying I'm just starting out using powershell/powershell forms so please forgive me if I am miss-understanding something. Having the installers coded directly into this form isn't really an option. In my ps1 file, each listbox item that is checked, when the "Install" button is clicked, fires off a series of scripts that install those programs. There are many custom things that we have to do with those programs in our environment that would not be solved by simply running the msi/exe file and inputing the arguments for those. I will attach the two scripts later.
User avatar
WSUsoftware
Posts: 30
Last visit: Thu Feb 17, 2022 2:52 pm

Re: Help with GUI

Post by WSUsoftware »

Here are the files. Hopefully this clears things up
Attachments
edit.psf
The powershell form that I want to flush out
(117.1 KiB) Downloaded 183 times
edited.ps1
My original working "handbuilt" gui
(13.28 KiB) Downloaded 188 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Help with GUI

Post by jvierra »

Just place the script file names in the checked listbox. When you process the "CheckedItems" list just retrieve the script name from the list and execute it. I have done this many times for many different things.

Create a CSV file with namss and scritp names.

Name,ScriptPath
Adobe,c:\scri[ts\installadobe.ps1
Office,c:\scritps\install_office.ps1
....
Just load this into the checkedlist and run the scrits for each checked item.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Help with GUI

Post by jvierra »

Here is yours as an example:
Attachments
edit.psf
(22.67 KiB) Downloaded 182 times
This topic is 8 years 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.
Locked