Results 1 to 4 of 4

Thread: Start/Stop Windows Services / indicator / progress bar

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    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.
    Attached Images Attached Images  

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Start/Stop Windows Services / indicator / progress bar

    duplicate post....my bad
    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

  3. #3
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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:
    1. Private Sub ApacheTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApacheTimer.Tick
    2.         ApacheProgressBar.Value += 1 [B]'just a little added shortcut[/B]
    3.  
    4.         If [B]ApacheProgressBar.Value = ApacheProgressBar.Max[/B] Then _
    5.                 ApacheTimer.Enabled = False
    6.  
    7.     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:
    1. Private Sub ApacheStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApacheStart.Click
    2.         ApacheProgressBar.Value = 0
    3.         ApacheTimer.Enabled = True
    4. [B]        btnApacheStart.Enable = False
    5.         btnApacheStop.Enabled = True[/B]
    6.         Shell("net start apache2")
    7.     End Sub
    8.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApacheStop.Click
    9.         ApacheProgressBar.Value = 0
    10.         ApacheTimer.Enabled = True
    11. [B]        btnApacheStart.Enable = True
    12.         btnApacheStop.Enabled = False[/B]
    13.         Shell("net stop apache2")
    14.     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

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Re: Start/Stop Windows Services / indicator / progress bar

    That was very helpful. Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width