|
-
Jun 2nd, 2003, 11:48 AM
#1
Thread Starter
Hyperactive Member
Starting a Windows Service
Project is made up of
form1.vb
service1.vb
When the user clicks on button1 on form1 i would like the service1 to run? and when they click on button2 i would like it to stop, does anyone know how to do this? thank you.
also can the service read variables in a moduale?
-gm
-
Jun 3rd, 2003, 11:31 AM
#2
Junior Member
The service can read an App.Config just like a regular .exe can.
I'm not sure if a form can start and stop a service.. I would think it could. I've always got around this by having the service launch a thread that does all the work. The service just starts and stops the thread. Doing this allows you to have a Form or a custom user interface to start and stop the thread that does all the work. It's also nice so when you debug you dont have to attach to the process of the service.
Hope this helps,
Joan
-
Jun 3rd, 2003, 01:09 PM
#3
Thread Starter
Hyperactive Member
start, stop service.
here is code that will stop and start a service for anyone that is interested.
Imports System.ServiceProcess
Public Class Form1
Dim myController As ServiceController
Private Sub mnuStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuStatus.Click
Try
Dim strMsgbox As String
myController.Refresh()
lblStatus.Text = "Status: " & "Windows service is currently " & LCase(myController.Status.ToString)
Catch err As Exception
Dim strMsgbox As String
lblStatus.Text = "Status: Make sure " & PublicVariables.strServiceName & " is installed on local machine."
strMsgbox = MsgBox("An error has occured, make sure " & PublicVariables.strServiceName & " is installed on local machine.", MsgBoxStyle.Information + vbOKOnly, "Windows Service")
End Try
End Sub
Private Sub mnuStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuStart.Click
Try
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
lblStatus.Text = "Status: Starting Windows Service..."
myController.Start()
Me.Cursor = System.Windows.Forms.Cursors.Default
lblStatus.Text = "Status: Windows service started successfuly"
Catch err As Exception
Dim strMsgbox As String
Me.Cursor = System.Windows.Forms.Cursors.Default
myController.Refresh()
lblStatus.Text = "Status: Windows service is currently " & LCase(myController.Status.ToString)
strMsgbox = MsgBox("Windows service is currently " & LCase(myController.Status.ToString), MsgBoxStyle.Critical + vbOKOnly, "Windows Service")
End Try
End Sub
end class
-
Jun 3rd, 2003, 01:11 PM
#4
Junior Member
here is code that will stop and start a service for anyone that is interested.
I knew there was a way! Thanks!
-
Jun 3rd, 2003, 01:46 PM
#5
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|