Support Forums

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.
User avatar
jvierra
Posts: 10017
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with GUI

Postby jvierra » Thu Jan 28, 2016 7:35 am

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: 661
Joined: Wed Oct 08, 2014 6:02 am

Re: Help with GUI

Postby dan.potter » Thu Jan 28, 2016 7:40 am

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: 661
Joined: Wed Oct 08, 2014 6:02 am

Re: Help with GUI

Postby dan.potter » Thu Jan 28, 2016 7:43 am

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

then he has start-process scriptpath.vbe.
User avatar
jvierra
Posts: 10017
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with GUI

Postby jvierra » Thu Jan 28, 2016 7:51 am

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?
User avatar
jvierra
Posts: 10017
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with GUI

Postby jvierra » Thu Jan 28, 2016 8:04 am

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.
User avatar
jvierra
Posts: 10017
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with GUI

Postby jvierra » Thu Jan 28, 2016 8:06 am

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
hamsandwich
Posts: 16
Joined: Thu Nov 20, 2014 12:05 pm

Re: Help with GUI

Postby hamsandwich » Thu Jan 28, 2016 8:49 am

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
hamsandwich
Posts: 16
Joined: Thu Nov 20, 2014 12:05 pm

Re: Help with GUI

Postby hamsandwich » Thu Jan 28, 2016 8:56 am

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 56 times
edited.ps1
My original working "handbuilt" gui
(13.28 KiB) Downloaded 58 times
User avatar
jvierra
Posts: 10017
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with GUI

Postby jvierra » Thu Jan 28, 2016 8:58 am

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.
User avatar
jvierra
Posts: 10017
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with GUI

Postby jvierra » Thu Jan 28, 2016 9:13 am

Here is yours as an example:
Attachments
edit.psf
(22.67 KiB) Downloaded 61 times

Return to “PowerShell GUIs”

Who is online

Users browsing this forum: Mitzen and 3 guests