 |
|
 |
Hi,
I have created one interactive service using a porperty "Allow service to intract with desktop"
And then while servie is running; in OnStart method one form is displayed.
My problem is that this form is loaded but not compeletly.
Service doesn't stops but i think it is in pause state at that moment.
I waited for some time but it dosent work out.
Plz help. ASAP
Amit
|
|
|
|
 |
|
 |
73amit wrote: I have created one interactive service using a porperty "Allow service to intract with desktop"
And then while servie is running; in OnStart method one form is displayed.
My problem is that this form is loaded but not compeletly.
Service doesn't stops but i think it is in pause state at that moment.
I waited for some time but it dosent work out.
Actually, I do not recommend that you use the "Allow service to interact with desktop" checkbox to accomplish this. Instead, create a brand new Windows Application, and use the "ServiceController" namespace to control your service.
Either email me your whole project (service and control form both), or post the relevant code here and I will be happy to take a look at it.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
 |
|
 |
hi,
I have to change service type through code; by giving user a configuration form to modify service type either MANUAL or AUTOMATIC or DISABLED..
Please help!!!!!
Amit Verma
|
|
|
|
 |
|
 |
Hello Amit,
You can do it, but its very messy, since by default the property is a readonly property. Here is what you need:
1. Add a reference to System.Management Library by going to "Project" and "Add Reference". You can NOT use an "Imports" statement to do this.
2. Main part of the code:
Dim sc As ServiceProcess.ServiceController
Dim csMachineName As String = "YourPCName"
Dim csServiceName As String = "YourServiceName"
sc = svcs.GetValue(GetServiceIndexNo(csMachineName, csServiceName))
StartMode(sc) = ServiceProcess.ServiceStartMode.Manual
' Options for Service Start Mode are:
' -----------------------------------
' ServiceProcess.ServiceStartMode.Manual
' ServiceProcess.ServiceStartMode.Automatic
' ServiceProcess.ServiceStartMode.Disabled
3. Function to get the index number for your service:
Public Function GetServiceIndexNo(ByVal MachineName As String, ByVal ServiceName As String) As Integer
Dim ServiceArray As ServiceProcess.ServiceController()
Dim ServiceIndexSelected As Integer
Dim i As Integer = 0
ServiceArray = ServiceProcess.ServiceController.GetServices(MachineName)
For i = 0 To ServiceArray.Length - 1
If ServiceArray(i).ServiceName = ServiceName Then
ServiceIndexSelected = i
Exit For
End If
Next
If IsNumeric(ServiceIndexSelected) Then
Return ServiceIndexSelected
Else
Return -1
End If
End Function
4. Public Property to set the startup type:
Public Property StartMode(ByVal sc As ServiceProcess.ServiceController) As System.ServiceProcess.ServiceStartMode
Get
Dim path As New System.Management.ManagementPath("Win32_Service.Name='" + sc.ServiceName + "'")
Dim manager As New System.Management.ManagementObject(path)
Dim mode As String = manager("StartMode").ToString()
Select Case mode
Case "Auto"
Return System.ServiceProcess.ServiceStartMode.Automatic
Case "Manual"
Return System.ServiceProcess.ServiceStartMode.Manual
Case "Disabled"
Return System.ServiceProcess.ServiceStartMode.Disabled
End Select
End Get
Set(ByVal Value As System.ServiceProcess.ServiceStartMode)
Dim path As New System.Management.ManagementPath("Win32_Service.Name='" + sc.ServiceName + "'")
Dim manager As New System.Management.ManagementObject(path)
manager.InvokeMethod("ChangeStartMode", New Object() {Value.ToString()})
End Set
End Property
I tested this on VS 2003, but it should work the same way on VS 2005.
Good Luck!
Pete
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
 |
|
 |
Thanks Pete,
I hope it will work as my need -- i am using VS 2005.
I will come back if any other information needed.
Amit
|
|
|
|
 |
|
 |
Just a quick tip:
In the ServiceProcessIntaller properties we can define which type of user will be used by default for this service (Local System / Network Service / Local Service / User).
If we choose any other than User, when the InstallUtil is done there is no need to define the user.
This can be changed later, through service manager.
Carlos Crespo
|
|
|
|
 |
|
 |
Carlos.Crespo wrote: Just a quick tip:
In the ServiceProcessIntaller properties we can define which type of user will be used by default for this service (Local System / Network Service / Local Service / User).
If we choose any other than User, when the InstallUtil is done there is no need to define the user.
This can be changed later, through service manager.
Carlos Crespo
You could do that. But if you are distributing your application to users on several different domains and don't know the login they will be using, it is easier to not hard code the login into the ServiceProcessInstaller. That was however a very good issue you pointed out though.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
 |
|
 |
Hi,
First, congratulations for a great article!
I am however having some problems with a issue that you didn't cover:
I would like to do a process every N seconds. I tried to had a TIMER, from the COMPONENTS TAB to the design view, enabled it from ONSTART, but it seems that the TICK event is never reached.
In fact i had a EventLog.WriteEntry to the DISPOSE event of the timer, and it seems that it is fired even before of the ONSTART???
So any idea about this?
TIA
Carlos Crespo
|
|
|
|
 |
|
 |
UPDATE:
I found the problem: and since this could be usefull for anyone else here goes:
I was led to a mistake: i add to the design pad of the service project the Timer control that was on my Components tab of the toolbox.
In fact i did add the SYSTEM.WINDOWS.FORMS.TIMER control, when in fact i want to add the SYSTEM.TIMERS.TIMER (they have the same icon....).
I was looking at the SimpleService sample (from MS QuickStart), and then i spot the diference.
This should be obvious for someone with more experience in VS2005 (i am just moving from VB6, so ...) at least since the events have different names (Tick and OnTimer), but anyway here goes the info.
BTW, if you want to have the system.timers.timer in your toolbox (and you are also begining in this platform...), you can add it by right-clicking in the toolbox and choose "Choose Items" and select the timer from the list.
Carlos Crespo
|
|
|
|
 |
|
 |
Hello Carlos,
Glad you like the article. You are absolutely correct. It sounds like you have found your solution, but just to clarify it for other users, here is basically the only way I have been able to get the timer to fire:
Class level variable:
Private coTimer As New System.Timers.Timer(10000)
Add a handler in "OnStart" event to the timer's elapsed event and enable it:
Protected Overrides Sub OnStart(ByVal args() As String)
AddHandler coTimer.Elapsed, AddressOf coTimer_Elapsed
coTimer.Enabled = True
EventLog.WriteEntry("MyService Started")
End Sub
Subroutine to take advantage of the timer:
Private Sub coTimer_Elapsed(ByVal pSender As Object, ByVal pArgs As System.Timers.ElapsedEventArgs)
EventLog.WriteEntry("Timer Fired!")
End Sub
That should do the job for you. Ironically enough this used to be a lot easier in VS 2003 for me.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
 |
|
 |
I am creating a service with multiple services. Is this possible because I am having several issues.
|
|
|
|
 |
|
 |
Sam Heller wrote: I am creating a service with multiple services. Is this possible because I am having several issues.
As far as it being possible, it is. What is the exact issue you are facing? Are you having issue during deployment? Also are you using a setup project or the Install Utility?
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
 |
|
 |
Yeah i thought it was. I have two services. Each have installers configured. I also have a setup project configured.
Install works fine and both services appear in service config tool. Both can be started and both continue to run. Only one though will let me debug. The other one just won't do anything. The breakpoint from a timer never triggers. Code is identical between services?
|
|
|
|
 |
|
 |
Sam Heller wrote: I have two services. Each have installers configured. I also have a setup project configured.
Install works fine and both services appear in service config tool. Both can be started and both continue to run. Only one though will let me debug. The other one just won't do anything. The breakpoint from a timer never triggers. Code is identical between services?
Some things you can double check if you are not hitting the breakpoint in a service:
1- Make sure you you have compiled the project in Debug mode.
2- Make sure you installed the version above that you compiled in debug mode.
3- Try running the service under the same username as you are logged in as.
4- Make sure you are attaching the correct service to the source code.
As far as the source code though, are you basically saying that you have renamed the same service to something else and installed it? I am not sure what you mean by "code is identical between services".
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
 |
|
 |
Ok i think I have a better understanding of where my issue lies. I am using VS2005. If I want to create two services within the same VS solution how do i go about it. One project, multiple services, or a project per service?
It would probably help if you could see what I can. Any chance I can mail you the solution and you could take a look. I am finding it very hard to find any usefull documentation any where on multiple services.
All help is greatly appreciated because I'm slowly losing my mind
|
|
|
|
 |
|
 |
Sam Heller wrote: Any chance I can mail you the solution and you could take a look.
Sure bud I can take a look at it. Just zip the whole solution up and send it to me at webmaster@digioz.com. Make sure to remove all compiled exe files from the solution before sending it.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
 |
|
 |
Hey,
Did you get my email with the solution? Sent it over on Friday
Any luck?
Thanks
Jon
|
|
|
|
 |
|
 |
Sam Heller wrote: Did you get my email with the solution? Sent it over on Friday
Hey Sam,
I just looked at it this morning. The problem with your project is that you are essentially trying to overload the "OnStart" and "OnStop" event twice, since you only have 1 Windows Service Project for the two services. Here is what I recommend you do to fix your problem:
1- Put either the "CompetitionDraw" or the "IntroducedCOmmissions" in its own windows service project.
2- Add the Primary Output of THAT new project to the Application folder in your installer.
3- Add the new Primary Output to the Custom Install action to install this new service seperately.
That should resolve your problem. Let me know.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
 |
|
 |
Pete your spot on with that. Or at least you seem to be.
I created a new project with a simple email every 10 seconds routine. Added an installer to it and then added it to the setup project under custom actions and it seems to be working fine. I did try this originally but seems like I must have had something wrong.
Anyway it's all good now so thanks. I suggest you put this into your further articles as I can see alot of other people running in to this.
Cheers
|
|
|
|
 |
|
 |
Sam Heller wrote: Pete your spot on with that. Or at least you seem to be.
I created a new project with a simple email every 10 seconds routine. Added an installer to it and then added it to the setup project under custom actions and it seems to be working fine. I did try this originally but seems like I must have had something wrong.
Anyway it's all good now so thanks. I suggest you put this into your further articles as I can see alot of other people running in to this.
Cheers
Glad to hear that solved your problem. I will definately add this as a special note on future parts of the article to help other developers who run into the same problem. Best of luck to you in your project.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
 |
|
 |
This article was a great help to me - thanks! I have a program that I've been wanting to convert to a service for a long time now but was intimidated by the process. I read your article and have now converted this app into a working service that will auto start with the PC.
Look forward to the remaining parts!
|
|
|
|
 |
|
 |
rFrank wrote: This article was a great help to me - thanks! I have a program that I've been wanting to convert to a service for a long time now but was intimidated by the process. I read your article and have now converted this app into a working service that will auto start with the PC.
Look forward to the remaining parts!
Glad to hear that Frank. Most programmers tend to stay away from windows services because of the unknowns. Good to hear that the article is useful for people.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
 |
|
 |
Can the call to installutil be done in a post install command in the setup project?
|
|
|
|
 |
|
 |
Brian Grant wrote: Can the call to installutil be done in a post install command in the setup project?
You COULD do that, although that is not the prefered method of doing it. I am going to cover this exact topic in part 4 or 5 of this article, but to give you a quick overview, all you would need to do is to add the executable file of the service under the "Custom Actions > Install" section of the setup project.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
 |