Archive for the ‘Window Services’ Category
How to Debug Window Service without installing
Posted by: admin in .NET, Window Services on September 3rd, 2010
Usually if we want to debug the windows service project to see if it is behaving as we expected, what we do is by installing the windows service and attaching that project to the process.
There is also another way to debug without installing it, what we need to do is by creating another project such as console project then copy and paste the code below.
-
Sub Main()
-
#If Not Debug Then
-
Dim servicesToRun As System.ServiceProcess.ServiceBase()
-
-
servicesToRun = New System.ServiceProcess.ServiceBase() {New MyService()}
-
System.ServiceProcess.ServiceBase.Run(servicesToRun)
-
#Else
-
Dim service As AS2Client.AS2SenderService = New MyService()
-
service.myentrysub()
-
-
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite)
-
-
#End If
-
-
-
-
End Sub
References:
Run Windows Service as a Console program
This service is marked for deletion
Posted by: admin in .NET, Window Services on September 9th, 2009
This error occurs when you uninstall a windows service.
What you need to do is to close the mmc or services.msc if this was opened.
More information of this error refer to KB Article
The service did not start due to a logon failure
Posted by: admin in .NET, OS, Window Services on July 8th, 2009
The “Appname” service failed to start due to the following error: The service did not start due to a logon failure
This error appears when starting a windows service, i also got this error when i was developing a windows service application using VB.net 2008.
If you try to look at the event logs under System Tools->Event Viewer->System, See the following is true;
- if you can see another error like “The <strong>’Appname’ </strong>service was unable to log on as <strong>’useracount’ </strong>with the currently configured password due to the following error: The trust relationship between this workstation and the primary domain failed. To ensure that the service is configured properly, use the Services snap-in in Microsoft Management Console (MMC).”
- The machine is a member of a domain.
What you need to do is rejoin the computer from the domain.
Mark for deletion Error when Installing Window Service
Posted by: admin in Exception, Window Services on May 26th, 2009
Problem
I got this error when I am trying to reinstall the Windows service after uninstallation. I did the following steps to re install the service.
a) I stopped the existing windows service using Administrative Tools –> Service
b) Keeping this Administrative tools –> Services window open, I tried to uninstall the service using InstallUtil.exe
c) I got the message “Service uninstallation successful”.
d) And then I tried installing the service again. It failed to install the service saying specified service has been marked for deletion.
Error message
An exception occurred during the Install phase. System.ComponentModel.Win32Exception: The specified service has been marked for deletion.
Cause
The registry entries related to the service are not deleted during the uninstallation. This error generally occurs when the service is uninstalled without stopping the existing service. However I got this error even when I uninstalled the service after stopping the service. This is because the Administrative Tools –>Services window is open when I was uninstalling the service. The registry entries are not deleted if the services window is kept open.
Solution
I found the following solution in newsgroups.
1. Stop the service
2. Close the Administrative Tools à Service window if it is open
3. Uninstall the service (only after closing the Administrative tools–> Services window. Opening the Services window during the uninstallation is the key reason why the above error is raised.)
4. Re Install the service again
Source: www.code101.com
Access Windows Service from Windows Application
Posted by: admin in .NET, VB.Net, Window Services on March 2nd, 2009
Accessing windows service from windows application is very easy task. Follow the steps
1. Open Visual Studio 2005/2008.
2. Add ServiceController Control into the form you just created.
3. Enter the Windows service name into the ServiceName Property of the ServiceController Control.
That’s all you need, other properties and methods are all self explanatory.
For more information about ServiceController click here
“Login failed error” when connecting to SQLServer From Windows Service
Posted by: admin in .NET, VB.Net, Window Services on February 28th, 2009
Your windows service is running under your LocalSystem account which obviously doesn’t have the correct privilidges to access the sql server. (DOMAIN\MachineName).
The reason this doesn’t happen in your winforms app is because this will be running under the user account you are logged into the machine as, which obviously does have the privilidges to access the sql server.
To grant your windows servce access rights to the sql server, you will need to set your service process installer to run under a user account, and define the credentials of a user who has access to the sql server,
Private Sub ProjectInstaller_BeforeInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.BeforeInstall
ServiceProcessInstaller1.Account = ServiceProcess.ServiceAccount.User
ServiceProcessInstaller1.Username = “Domain\account”
ServiceProcessInstaller1.Password = “password”
End Sub
or you can change the account type using service property from service.msc (administrative tools->Services) and locate the windows service you have created.
Properties->Log On Tab, select this account and browse.
How to use Timer in Windows Service
Posted by: admin in .NET, VB.Net, Window Services on February 28th, 2009
You cannot use Timer Control in windows service it is because Timer Control is located at System.Windows.Forms.
Instead, use server timers from Timer namespace. To do this,
Friend WithEvents mTimer as New Timer.Timer
Protected Overrides Sub OnStart(ByVal args() As String)
mTimer.Interval = 6000 ‘6 seconds
mTimer.Enable = true
End Sub
Private Sub mTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles mTimer.Elapsed
‘Put your code here to execute
End Sub