Start/Stop Windows Services / indicator / progress bar
I need to create an application, that will have 2 buttons, to start and stop a windows service. If i make the first 2 work, more butons for more services will follow of course. There should also be a progress bar showing the service starting or stopping, and also an indicator showing if the process is started or stopped.
I have been working on Microsoft visual studio 2005 and VB .NET for the past 24 hours, and this code is what I've got so far.
Code:
Public Class ControlPanel
Private Sub ApacheStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApacheStart.Click
ApacheProgressBar.Value = 0
ApacheTimer.Enabled = True
Shell("net start apache2")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApacheStop.Click
ApacheProgressBar.Value = 0
ApacheTimer.Enabled = True
Shell("net stop apache2")
End Sub
Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApacheProgressBar.Click
ApacheTimer.Enabled = False
ApacheProgressBar.Value = 0
End Sub
Private Sub ApacheTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApacheTimer.Tick
ApacheProgressBar.Value = ApacheProgressBar.Value + 1
If ApacheProgressBar.Value >= 10 Then _
ApacheTimer.Enabled = False
End Sub
End Class
The progress bar does not totally fill. It just fills up to a point and just stays there. Also, i have no idea how to add an indicator to show if the process is started or stopped. I have no previous programming experience.
Re: Start/Stop Windows Services / indicator / progress bar
Hi,
regarding the process bar, what is the max value. if it is greater that 10, then you should see it progress part way and stop. You could change a line in the timer_tick routine to fix it also. I.e.
VB Code:
Private Sub ApacheTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApacheTimer.Tick
ApacheProgressBar.Value += 1 [B]'just a little added shortcut[/B]
If [B]ApacheProgressBar.Value = ApacheProgressBar.Max[/B] Then _
ApacheTimer.Enabled = False
End Sub
that will allow that pBar to go all the way
To give an indication of whether it is started or not maybe something like this
VB Code:
Private Sub ApacheStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApacheStart.Click
ApacheProgressBar.Value = 0
ApacheTimer.Enabled = True
[B] btnApacheStart.Enable = False
btnApacheStop.Enabled = True[/B]
Shell("net start apache2")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApacheStop.Click
ApacheProgressBar.Value = 0
ApacheTimer.Enabled = True
[B] btnApacheStart.Enable = True
btnApacheStop.Enabled = False[/B]
Shell("net stop apache2")
End Sub
Another thing I just noticed is that you are using the same timer routine for starting and stopping. When when stop the service, you are using the pBar code used for starting the service. I'm not sure what you want to do, but to show the pBar going down when you stop, then you either need another time who's tick event reduces the time, or you need to get a funky in the tick event to recognize when the bPar needs to go up and when it needs to go down.
HTH
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers.
A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________
Last edited by kebo : Now. Reason: superfluous typo's