Start/Stop Windows Services / indicator / progress bar

Nucleus

Active member
Joined
May 24, 2005
Messages
30
Programming Experience
Beginner
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.

VB.NET:
 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[size=2][color=#0000ff]
[/color][/size]
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.
 

Attachments

kulrom

Well-known member
Joined
May 10, 2005
Messages
2,854
Location
Republic of Macedonia
Programming Experience
10+
Hi,
I'm not so sure that I understand your question, but i'll try to help you :)

If Maximum properties of certain Progressbar is 100 it's kind of normal that it will stop after 1/10 as you have made it to behave like that ...
PHP:
 If ApacheProgressBar.Value >= 10 Then 
ApacheTimer.Enabled = False
If you want to make it fills whole bar then do this:

PHP:
 If ApacheProgressBar.Value >= 100 Then 
ApacheTimer.Enabled = False
about an indicator to show if the process is started or stopped you could take a look at this threads ... http://www.vbdotnetforums.com/showthread.php?t=3136 it may help you out ...


Cheers ;)
 

Nucleus

Active member
Joined
May 24, 2005
Messages
30
Programming Experience
Beginner
That was very helpful. Thank you very much. :)
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,322
Location
Sydney, Australia
Programming Experience
10+
The ProgressBar in .NET 2.0 (used by Visual Studio 2005) has some new functionality. Given you aren't actually showing progress from 0 to 100%, but rather just that something is happening, it is more correct to show a continuos progress bar. You do this by setting the Style property to Marquee. The only problem is that you need to know when the service has actually started or stopped to know when to stop the ProgressBar, which is done by setting the Style to either Blocks or Continuous.
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
Instead of using a shell command you could/should use a servicecontroller.
 

kulrom

Well-known member
Joined
May 10, 2005
Messages
2,854
Location
Republic of Macedonia
Programming Experience
10+
Top Bottom