Powershell Studio 2015 visual indicator update real time?

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
User avatar
stratagem
Posts: 6
Last visit: Mon Feb 15, 2016 10:43 am

Powershell Studio 2015 visual indicator update real time?

Post by stratagem »

Sorry for the poor subject line. I'm not sure how to word it exactly.

What I'd like to do is create some visual indicators for the users showing if a service is running or not. Maybe change a label box or picture box to red / green depending on the status? Is it possible to have this job running in the background separate from the button clicks and have it update the boxes in real time?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell Studio 2015 visual indicator update real time?

Post by jvierra »

Yes - You can use a timer tick to do this.
User avatar
stratagem
Posts: 6
Last visit: Mon Feb 15, 2016 10:43 am

Re: Powershell Studio 2015 visual indicator update real time?

Post by stratagem »

Thanks! I'll read more on timers.
User avatar
stratagem
Posts: 6
Last visit: Mon Feb 15, 2016 10:43 am

Re: Powershell Studio 2015 visual indicator update real time?

Post by stratagem »

I'm having a hard time working this out.

Would it be best to create this function, if it should be a function, in the form_load section or before that? And then have a function for each label call on the timer?

Sorry, I'm still learning Powershell and most of my scripts have been one-liners. I still have a long ways to go...
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell Studio 2015 visual indicator update real time?

Post by jvierra »

Why do you need functions to change a labels color?
User avatar
stratagem
Posts: 6
Last visit: Mon Feb 15, 2016 10:43 am

Re: Powershell Studio 2015 visual indicator update real time?

Post by stratagem »

I'm using this method as feedback for the end users. Right now when I click start or stop it works but it doesn't provide any indication that it's finished. So the user has to trust that it is working and remember which services they have either started or stopped.

Functions might not be what I need. I'm unsure on how to solve this problem.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell Studio 2015 visual indicator update real time?

Post by jvierra »

What does that have to d with functions.

You are way too vague for me to be able to answer. What are you doing? What and how many services? What is the purpose?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell Studio 2015 visual indicator update real time?

Post by jvierra »

You asked bout timers. What do the timer and the button have to do with each other?
User avatar
stratagem
Posts: 6
Last visit: Mon Feb 15, 2016 10:43 am

Re: Powershell Studio 2015 visual indicator update real time?

Post by stratagem »

Sorry, not trying to be vague.

It's a small form that stop/starts about 15 different services spread over 3 different servers. The labels themselves are only there to show if the service is running. That's it.

So something like this...

If ($Service.Status -eq "Running")
{
$label1.Text = "Running"

}
Else { $label1.Text = "Stopped" }

}

I need it on a timer or something else that will automatically update the labels every X amount of seconds.
Hopefully that clears it up.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell Studio 2015 visual indicator update real time?

Post by jvierra »

Here is an easier way to handle that..
  1. $timer_tick={
  2.     $services= 'service1', 'service2', 'service3'
  3.     $services=$computers|
  4.         ForEach-Object{
  5.             Get-Service -Computer $_ -Name $services
  6.         } |
  7.     select MachineName,DisplayName, Status
  8.  
  9.     $datagridview.DataSource=[collections.arraylist]$services
  10. }
We can also use a list view with images or a checked listbox.
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