Checkbox Question

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 5 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
KAyGt3
Posts: 5
Last visit: Wed Nov 22, 2023 12:08 am

Checkbox Question

Post by KAyGt3 »

Product, version and build: Powershell Studio, 5.6.158.0
32 or 64 bit version of product: 64 bit
Operating system: Windows 10
32 or 64 bit OS: 64bit

Hello,

i modify the attached script to get all running process on my Windows 10 machine.
ListProcess.psf
(27.32 KiB) Downloaded 97 times
What i want is: When i click on "Load View" button, generate the list of all process running. After i checked the process that i want to kill and i click on "Kill Process" button to kill it.

How can i do it? Anyone can help me?

Thanks!
Marco
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Checkbox Question

Post by davidc »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Checkbox Question

Post by jvierra »

Have you looked at the "Spotlight" article for the control?

Right click on the "ListView" control in the toolbox for the documentation and support articles. They will explain with examples, how to use a ListView. Most controls have useful articles on the right-click menu (context menu).
KAyGt3
Posts: 5
Last visit: Wed Nov 22, 2023 12:08 am

Re: Checkbox Question

Post by KAyGt3 »

jvierra wrote: Tue Feb 12, 2019 3:11 pm Have you looked at the "Spotlight" article for the control?

Right click on the "ListView" control in the toolbox for the documentation and support articles. They will explain with examples, how to use a ListView. Most controls have useful articles on the right-click menu (context menu).
Ok, i'll take a look! :D

Thanks!
KAyGt3
Posts: 5
Last visit: Wed Nov 22, 2023 12:08 am

Re: Checkbox Question

Post by KAyGt3 »

I looked at Spotlight but it didn't help, may someone can help me :D

I attached the modified script
ListProcess.psf
(25.4 KiB) Downloaded 95 times
Now when i click the button and at least one checkbox is checked, returns a message.

What i want is: After i press the button, every checkbox is checked execute "Stop-Process -Name $ProcessName".

Thanks!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Checkbox Question

Post by jvierra »

You code is faulty. You can not use the event script block to test for checked items. You must enumerate the items and get the checked state.
KAyGt3
Posts: 5
Last visit: Wed Nov 22, 2023 12:08 am

Re: Checkbox Question

Post by KAyGt3 »

OK, i modified a little bit.
  1. $buttonLoadView_Click={
  2.     $Process = Get-Process
  3.     foreach($proc in $Process)
  4.         {
  5.         Add-ListViewItem -ListView $listview1 -Items $proc.ProcessName
  6.         }
  7. }
Will be very helpful if you can write a little example, i'm stuck right now.

Thanks!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Checkbox Question

Post by jvierra »

Code: Select all

$buttonStopProcess_Click={
	$listview1.CheckedItems |
        ForEach-Object{
		    Write-Host ("Item checked " + $_.Text)
            #Stop-Process $_.Text
	    }
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Checkbox Question

Post by jvierra »

KAyGt3 wrote: Thu Feb 14, 2019 12:29 pm OK, i modified a little bit.
  1. $buttonLoadView_Click={
  2.     $Process = Get-Process
  3.     foreach($proc in $Process)
  4.         {
  5.         Add-ListViewItem -ListView $listview1 -Items $proc.ProcessName
  6.         }
  7. }
Will be very helpful if you can write a little example, i'm stuck right now.

Thanks!
Not what was wrong. You need to look at my code above. You also need to re-read the spotlight and MSDN articles on how to use a ListView.
KAyGt3
Posts: 5
Last visit: Wed Nov 22, 2023 12:08 am

Re: Checkbox Question

Post by KAyGt3 »

jvierra wrote: Thu Feb 14, 2019 12:31 pm

Code: Select all

$buttonStopProcess_Click={
	$listview1.CheckedItems |
        ForEach-Object{
		    Write-Host ("Item checked " + $_.Text)
            #Stop-Process $_.Text
	    }
}
Now i understand where i'm wrong!

I have a lot of things to study, thanks for your help!
This topic is 5 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