Click here to Skip to main content
15,891,372 members
Everything / Windows service

Windows service

Windows-service

Great Reads

by Mustafa Kok
Easily debuggable Windows service project template written in C#
by Shuqian Ying
Implementing the user account setting part of Membership+ management system.
by Matthew Dennis
A utility to run Redis, or other executables, as a Windows Service.

Latest Articles

by Fredrik Rudberg
A Windows service that removes files older than a specific date from a configurable set of folders
by Mustafa Kok
Easily debuggable Windows service project template written in C#
by Alon Lek
HostMe is a simple one EXE application that can host your static web pages easily. It can run either as a console or as a Windows service with the minimal amount of effort from your side.
by Shesh Lamichhane
Step by step to add the transformation files of app.config in your .NET Windows service

All Articles

Sort by Score

Windows service 

21 Jul 2019 by Mustafa Kok
Easily debuggable Windows service project template written in C#
11 Jul 2012 by Mehdi Gholam
Usually such functionality is done with a windows service, create a service for your DLL and call your methods on a Timer.Read the following :http://msdn.microsoft.com/en-us/library/aa984464%28v=vs.71%29.aspx[^]Simple Windows Service Sample[^]
18 Mar 2011 by Sergey Alexandrovich Kryukov
Most probably the window you need is not the foreground window. It works in most cases, but can fail to get desired effect when the application runs a dialog.To do the next step, you should use P/Invoke. Windows is very naughty, what you thing is obvious may be not what you want.So...
11 Jul 2012 by Sergey Alexandrovich Kryukov
Please see my comment to the question. The problem is that you don't specify what do you mean by "run a DLL", so your problem cannot be solved until you understand what you really need.For better understanding, you should understand what the executable modules are and what is the role of...
13 Feb 2011 by Espen Harlinn
What you probably want, can easily be accomplished using the Task Scheduler API[^]You can use something like this A New Task Scheduler Class Library for .NET[^] to develop your solution in c# or just import the COM interfaces yourself.The really easy solution is to use the tools included...
15 Feb 2011 by Pravin Patil, Mumbai
I would suggetst you to use Quartz.Net for this. It is an open source framework. Moreover it is best suited for small to big projects.You can find more information on Quartz.Net at1 . http://quartznet.sourceforge.net/tutorial/lesson_1.html[^]2....
15 Feb 2011 by JF2015
Hi,you could just rename the filename before saving with this code:string fileName = "C:\\abc.xlsx";string renamedFile = Path.GetFileNameWithoutExtension(fileName);renamedFile = renamedFile += "_" + DateTime.Now.ToShortDateString() +...
16 Mar 2012 by Wayne Gaylard
If you are using Windows Scheduler to start the service, it might be better just to use a simple Console Application instead of a windows service.
16 Mar 2012 by Dylan Morley
As Wayne has said, you don't need a windows service for this. You want to do something at a particular time or interval? Then use the scheduler and simply have it execute a Console Application or a windows forms application, just with no UI. :)Introducing a windows service just over...
3 Apr 2012 by OriginalGriff
Check that you are correctly disposing all of your objects - it sounds like some resource (such as SqlCommand, SQlConnection etc.) is not being released properly. If this does not cause memory problems (and it won't, they don't take a lot of space) then the GC is not kicked in to call Dispose to...
18 May 2012 by OriginalGriff
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...A very quick search gave over 10 million results: https://www.google.co.uk/search?sugexp=chrome,mod=7&sourceid=chrome&ie=UTF-8&q=connect+to+service+c%23[^]The fourth...
13 Aug 2012 by sunder.tinwar
Hi Guys,I have a window service which is installed by user and setup to run under context of domain administrator account. I am not storing these credentials anywhere.Reinstalling parallel service will not be a solution for me, as I will not have those credentials again and other...
5 Apr 2016 by F-ES Sitecore
Is Outlook installed on the machine? For what it's worth, you're not going to get this working, Outlook is not suitable for automation from environments that have no interactive desktop. What happens if Outlook needs to show a dialogue box or prompt or error? Who is going to click "ok" when...
3 Jun 2016 by Dave Kreskowiak
You said processes, so you mean like this[^]?
19 Aug 2019 by OriginalGriff
Windows services cannot have a user interface, nor can they start or run any application which does have a user interface - because a user interface requires a user to be logged in, and services can run without a user (because they don't run under the user account; they can be run when the OS...
23 Apr 2012 by Thoughtweaver
Hi!When you initialize the service, you have to set the "CanHandleSessionChangeEvent" property to true. It is set to false by default. You also need to enable other service abilities explicitly:EDIT: Where the service component is initialized:private void InitializeComponent(){ ...
10 Aug 2010 by OriginalGriff
See the Timer class in MSDN....................
27 Sep 2010 by Varun Sareen
Dear Friends,I am running a window service in which the data is fetched from the access sheet into a datatable and then with the help of foreach loop; A XML file is created in the bin/debug folder of the same project and the same information with the Id and Details is written into the XML...
9 Oct 2010 by Sandeep Mewara
Ok. Lets pick an example, a real life scenario:You need to send an email every monday to all the users registered to a given webstite. You can have this windows service in place that will keep running - every monday it will automatically send the email with content specified. You don't need to...
9 Oct 2010 by Jörgen Sigvardsson
Services, unlike normal programs, need not run in the context of an interactive session. So whenever you need something to be done, without the need of having anyone log in, a service is a good way to deal with the problem.Of course, services come with a whole different bag of problems: you...
22 Oct 2010 by Jslw
I have a windows service which is written in C++ using VS2005. I also use the VS2005 to create the installer. The installer is working fine with Win XP but I run into UAC(User Account Control) Windows 7. My windows service does not register into Services database. In my installer, there are...
2 Dec 2010 by knaf
Hi,I need to get notification when there is a change in the display settings (resolution, orientation, relative position and when a monitor is being connected/disconnected) of multiple monitors connected to my computers from within a Windows Service (can't listen to WM_DISPLAYCHANGE) . I can...
8 Dec 2010 by Alain Rist
Hi Sergey,There is a C service sample in the Win7 SDK[^] at C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\winbase\service.cheers,AR
13 Jan 2011 by #realJSOP
The best you can do is enumerate all currently inserted USB storage devices (and handle the add/remove system events for such devices), and then use the SystemFileWatcher object to monitoir those drives. I wrote a 2-part article series about using the FileSystemWatcher object that you might...
1 Feb 2011 by #realJSOP
Is there something special about making a Windows service run as a WCF client?I've written the following:- A Winforms app that acts as a WCF ServiceHost- A Winforms app that acts as a WCF client- A Windows service that acts as a WCF clientThe WCF stuff uses NamedPipe...
4 Feb 2011 by Manfred Rudolf Bihy
String host = "www.somehost.com"; //In your case you'd take this from the fileString mac = "MAC";String url = String.Format("http://{0}/FolderName/downloads.aspx?MAC={1}&dtype=win", host, mac);// Do something with your dynamically created url here
16 Feb 2011 by #realJSOP
You should use a thread instead of a timer. Here's your code rewqorked to use a thread, and to abstract out some of the code into discreet methods (monolithic methods are so 1980's). Keep in mind that I merely typed this into the editor here at CP, so it will probably require a tweak or two to...
1 Mar 2011 by Dave Kreskowiak
You can't do it from a service. You'd have to load each user registry hive and poke the value in, then unload the hive, for each account on the machine. Even with just a few accounts, this can be a VERY time consuming process. This is better done simply using Group Policy alone instead of...
18 Mar 2011 by manushi88
Hi,I need to write a console/Window Service application in C# using Visual Studio 2005 which will run 24X7 on a system.Requirements are 1)An event should fire every 5 minutes to findout out which is current active window(which have keyboard focus) running on a system2)write it into text...
8 Apr 2011 by Dave Kreskowiak
Won't work. SharePoint Server 2010 requires a 64-bit processor and O/S, no exceptions.
13 Apr 2011 by Nish Nishant
From Vista onwards, services cannot interact with the UI. So calls like GetForegroundWindow will not work. This is by design.The workaround is to have a stub client application that calls GetForegroundWindow and communicates with the service. For any UI function, the service proxies through...
16 Apr 2011 by Zhibo_Luo
This maybe useful to you:www.hellboundhackers.org/forum/keyboard_hook_from_service_application-22-6951_0.html
27 Jun 2011 by Vivek Krishnamurthy
Have a look at the link How to create a setup project for a Windows Service application in Visual C# [^] it is explained with detail and sample.
30 Aug 2011 by Dylan Morley
A windows service is not really meant to work like this, a service is 'constantly running' rather than interval based. Your best bet here is just to write a standard program and have it execute under 'Scheduled Tasks' which will handle all of your issues
2 Sep 2011 by Tejas Vaishnav
Hello Friend...After installing your service you need to start it....1) Goto Control Panel..2) Administrative tools3) Services4) Find your service5) Right Click and start it6) Now your service will start and working....other wise 1) Press WindowsKeY + R2) In Run type...
6 Sep 2011 by Sergey Alexandrovich Kryukov
First, avoid timers by all means. Use a separate thread instead with System.Threading.Thread.Sleep. This is much more reliable and more straightforward to program.Secondly, it's hard to see you problem without looking at your code. Services are harder to debug. Use...
6 Sep 2011 by Ganesan Senthilvel
To identify the problem, could you put try.. catch blocktry{....}catch (Exception ex){... ex.Message....}It will catch the root cause for this service issue. From that, you can fix the problem which stops the service. My gut feeling is that there may be few...
9 Oct 2011 by Mehdi Gholam
Read the following links :POSIX and OS/2 are not supported in Windows XP or in Windows Server 2003[^]WINNT POSIX[^]
13 Mar 2012 by #realJSOP
More seriously, you would have to either configure the router to doisallow access to a certain URL, or you would have to establish a group policy for the domain and push it out to the workstations. The group policy could be something as simple as a HOSTS file that redirects the URL to localhost...
20 Apr 2012 by Sergey Alexandrovich Kryukov
The concept of Windows Service application is very wide, it can be nearly anything, and the notion of login is not part of it. There are no limitations in your service architecture preventing you from using any authentication schema and communication mechanism you may want. It means that it all...
18 May 2012 by Zoltán Zörgő
You need IPC (inter-process communication)There are several techniques. It really depends on you, because you can use a simple file, registry, remoting, wcf, basic tcp/ip sockets, msmq....
18 Jul 2012 by Zoltán Zörgő
Bypassing Session 0 isolation[^] is not really possible[^] as I know. Impersonating a user does not mean that you get access to it's session.Is the service really necessary, isn't enough to make the client start trayes on logon?Or if you can not modify the client, you could make a fourth...
1 Jan 2014 by mrhassell
http://odetocode.com/blogs/scott/archive/2004/10/29/createprocessasuser.aspx[^]
18 Feb 2014 by Raul Iloc
Your service run on a default user like "LocalSystem" that may have limited rights, so you have two solutions:1)create a new user on your server then give it to them access rights, then start your service by using this new user;2)give the access rights to the existing default user used by...
23 Apr 2016 by Dave Kreskowiak
Googing this you'll find that you can NOT use Outlook interop, or any Office application, inside a non-interactive session, like a web site or a Windows service app. It is not a supported solution. It MAY work here and there, but it is not guaranteed to work all of the time.
3 Aug 2017 by Richard MacCutchan
Windows services do not run in a session which has access to a terminal (desktop). That is to say no screen or keyboard (logical or physical) is attached. So bottom line is you cannot do this from a service. And, to be honest, that is just as well as such a feature would open a huge security...
22 Aug 2018 by Pal Sayantan
I developed a windows service in C#. I followed some existing tutorials from google. In service.cs class the constructor is only holding the InitializeComponent() method. In OnStart() method I have written some code to open a port using TCPClient to connect via tcp connection to some other...
22 Aug 2018 by Jochen Arndt
TcpListener.AcceptTcpClient() is a blocking call. As a result, your OnStart() method will only return when a client has connected. But the start routine of a service should return as soon possible. If it runs for a too long time, the service control manager will give up waiting for the function...
19 Aug 2019 by Maciej Los
Please, read this: .net - How can I run an EXE program from a Windows Service using C#? - Stack Overflow[^] The most important information is: Quote: Windows Services cannot start additional applications because they are not running in the context of any particular user. Unlike regular...
26 May 2020 by OriginalGriff
You can't open a GUI app from a service at all: the whole idea is that services do not have any interaction with the user (directly or indirectly) and they do not run under a "normal user" account for that very reason - that's why they can open...
16 Apr 2021 by Richard Deeming
Try replacing: cmd.Parameters.Add($"@p{i}") with: Dim p As SqlParameter = cmd.CreateParameter() p.ParameterName = $"@p{i}" cmd.Parameters.Add(p)
30 Jan 2022 by Graeme_Grant
What have you tried so far? There is a Dot Net API for converting to/from classes & raw XML. This Google search has many examples to point you in the right direction.
16 Mar 2023 by OriginalGriff
You can't. Services cannot have any user interface because they can run when there is no logged in user - and in an isolated session. The isolated session means there is nowhere for an app to run, so a Service can't start any app. You would need...
24 Jun 2010 by lingareddy
1)I have developed one windows service and I have taken reference of COM library.The windows service functionality is need to access and open network drive files, I kept ServiceProcessInstaller account as LocalSystem it is working fine and executing COM library functionality but when I change...
24 Jun 2010 by dan!sh
You need to check whether the user account under which the service runs is having rights to access the files or not.
4 Jul 2010 by Richard Andrew x64
In Vista and Windows 7, services execute in a different session from the user's applications. This means they cannot interact with any windows from the user's apps.
12 Jul 2010 by Shining Legend
We have a requirement as below.At the end of every day, the .NET application should calculate for how much time the Outlook was open on the computer.Please help me how can I do this task.
12 Jul 2010 by LNogueira
You can build a windows service, that periodical checks if process "outlook.exe" is running, if it is then your service starts tracking usage time.
22 Jul 2010 by Shining Legend
I have to write code in C#,In a Windows Service, How to continuously keep checking if outlook process has been opened or not. If outlook is opened it has to write the open time of outlook in a file. If outlook is closed it has to again write the close time of outlook in a file.
23 Jul 2010 by Jimmanuel
The Process.GetProcessesByName[^] method can test for a running instance of Outlook for you. If it's running then you can take the Process object that's returned and subscribe to the Exited[^] event. From here, you can look at the Process object again and use the StartTime[^] and ExitTime[^]...
23 Jul 2010 by Shining Legend
YEs I have gone through the link content posted in previous answer and I can track the time when the process exits. But i need to build windows service in such a way that it should automatically detect if the outlook is opened and save that time in notepad.
8 Aug 2010 by bonypatel
Hi..allI want to create an Application using C# (Visual Studio 2008),My app process is expected to monitor the copy-paste file process that is doing by the current logged user.But the problem is that,I give only one path to FileSystemWatcher object. I monitor my all drive. But it can't...
8 Aug 2010 by E.F. Nijboer
You can simply use a FileSystemWatcher for each drive. Simply create a list or vector and for each drive you add a FileSystemWatcher.Good luck!
9 Aug 2010 by pl_joyous@yahoo.co.in
I am successful in hooking windows Nt functions (registry and file systems and create process functions). I could hook all exes, however, when the control transfers to service, it is not hooking both registy and file system.Hence I started analysing about hooking services. Ijust have to hook...
20 Jan 2015 by bonypatel
Answer from other guys, It helpful to other coder.protected override void OnStart(string[] args){string[] drives = Environment.GetLogicalDrives();_watchers = new FileSystemWatcher[drivers.Length];int i = 0;foreach (string strDrive in drives){FileSystemWatcher...
10 Aug 2010 by Wanlambok
Hi, I want to create a windows service that will continously query the database for a change in any row and then execute another program if any change is found.Kindly help me!!Thanks
10 Aug 2010 by Abhinav S
What part of your question are you having a problem with?If you want help to create a windows service, see here[^].
10 Aug 2010 by Wanlambok
Hi I want to create a windows service that query the database for every 2 minutes.I used the Visual studio 2005 IDE.please suggest me some solution.Thank you
10 Aug 2010 by tiggerc
You need to create a service application, and have it install, for which you need a service installer, included in your application, Search for creating a system service vb.net.See hereInstead of using a timer component you need to use a threading timer because the timer component on the...
10 Aug 2010 by #realJSOP
You've already identified the solution - create a windows service. Go forth and code.
7 Sep 2010 by Jitendra Zaa
Hi,Log4net is working fine in my windows application but whenever I use same config in Windows service, Rollingappender does not work.All logs are written in same file. If you know some thing about this behavior then please reply.Find the config setting:
7 Sep 2010 by Dylan Morley
Have you added the 'Watch Configuration' to your Service assembly? e.g. using XML configurationlog4net.Config.XmlConfigurator.ConfigureAndWatch( new System.IO.FileInfo("log4net.config"));e.g or the DOMConfigurator (deprecated?) assembly attribute// Log4Net watch XML...
21 Sep 2010 by aidin Tajadod
Hi,I have a Server (Win 2003) with about 16GB RAM.I have a windows service installed on this machine. For this Windows Service, Task Manager shows me something about 20/Sec Pagefault. I have too much Free RAM, why should I have Page Fault? Note:This Windows Service writes about...
5 Oct 2010 by Sahar1287
Hi everyone,I coded a library that allows to create unlimited instance of any service, in the following format:"MyService1" have logSource "1MyServiceSource" and Log "1MyServiceLog""MyService2" have logSource "2MyServiceSource" and Log "2MyServiceLog"....In fact i'm storing the...
7 Oct 2010 by lesora
Yes, I tried some google's links but I didn't find better than http://msdn.microsoft.com/en-us/library/aa364399(VS.85).aspx[^]which is not what I'm really looking for :(Thanks for answers
6 Oct 2010 by nitinrd
Dear Friend it is very powerfull utility as I seen. But on some of the machine I am facing following problemWhen I run the application in the commnad prompt RemoteUnlock.exe hostname Error displayed isERROR: Remote service did not start successfully: 997What could be the problem? There...
7 Oct 2010 by Dave Kreskowiak
You probably don't have the authorization to start a service on the remote machine.Or the service that it's trying to start isn't registered properly or is failing to start for some reason.
9 Oct 2010 by Ashok Gowtham
I recently learnt how to create windows service.(Simple Windows Service Sample[^])But, however, I have a question: What do you use them for? ... and HOW?Of course we see a lot of services on windows for different purposes.I just wanted to know how to do something other than a typical...
7 Oct 2010 by nitinrd
Dear Dave,Thank you fo your reply.I am a local and domain administartor for all the workstations here at my office. I look after desktop,server and network administration.Above problem mentioned is mainly for all my windows XP 64Bit workstations. On 32Bit I don't have any problem to...
12 Oct 2010 by unifeb45
Hi,I have a windows service which is working on my local computer properly but it does not work on another computers. I made the setup project for that service and install the other computer but it still not working. Any suggestion ?Thanks.
13 Oct 2010 by Thomas Krojer
Did you check the account setting for the service?
20 Oct 2010 by Sasmi_Office
Dear Friend's,I need a help regarding my offline system...I have created one project which is Window Application this application will be work in different branches in india as well as abroad.This application is done by Front-End Visual Studio 2005 (version 2.0) and Back-end as...
20 Oct 2010 by Rajesh Anuhya
Use the web service to achieve this easily Go throgh the below link for more info.Web Serivces in .Net[^]
26 Oct 2010 by Ahmad Sakaji
--> Start--> Run and type cmd in the Open: line --> Click OK.--> sc Delete --> Reboot the system.
9 Nov 2010 by JeremH
Hi,With your BackOffice, you call your webservice method (.asmx) wich called "GetDataArray(....)" helped of your database ( Stored process). I don't know if it is the help waited but your question is too largegood luckjerem
9 Nov 2010 by thatraja
I guess you didn't selected Local System for Account value for Service Process Installer which is used in Service.Anyway, Go through this article which involves step by step, it will surely help you.Working with Windows Service Using Visual Studio 2005[^]
9 Nov 2010 by Rajesh Anuhya
.net Remoting Concepts may helps you.., Try it.. :rose::rose:
9 Nov 2010 by Shining Legend
I have created a Windows service in WindowsServer 2003 machine. but When i install it using Visual Studio command Prompt using InstallUtil utility. It gives a message that installation is successful but it doesnt show up in the Services list. I tries to reboot the computer but still its not...
9 Nov 2010 by kunal naik
Hello,I have a table in a SQL Server 2008 data base.Can it be possible, through Windows Service we canfetch the data from data base and show in a web pagegrid view? I have get this through web service but I want to know thatcan it be possible through windows services and...
9 Nov 2010 by Rajesh Anuhya
Here is the Solution for youhttp://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx[^]:rose::rose::rose:
2 Dec 2010 by E.F. Nijboer
To detect the orientation (or change in orientation) is the most easy part of the problem. There is no display resolution that has the same width and height, so the orientation changes if the vertical becomes the horizontal resolution an vice versa. It is also possible to say that the width is...
6 Dec 2010 by ely_bob
I think your issues are involved in your Threading.. Most likely tied into the Disposal... check to see which objects are actually getting disposed of... It sounds like your dispose is being called oin the wrong object from a different thread... Use the pattern class myThreadWorkerClass...
8 Dec 2010 by Kozlov_Sergey
What should i know to write Windows 7 service?I have used article about Windows service.I creaded service for Windows.It works in Windows XP, but does not work in Windows 7.Can someone write write article about writeing Windows 7 services in C++?
8 Dec 2010 by #realJSOP
Wow - if there was ever a question that should answered "google is your friend", this is it.Writing a Windows service for Win7 is no different than writing any other windows service execpt for the increased user restrictions. So, write your service with that in mind.
12 Dec 2010 by kubi081
Hi,I have done a windows service in c# but I'm having error since I started the service. I have searched for the solution but I couldn't find one yet.If anyone faced with the same problem please help me.The error says:error 1053 the service did not respond to the start or control...
12 Dec 2010 by Manfred Rudolf Bihy
In the services OnStart handler you are either taking to long (max 30 secs)or even never exit. Please use OnStart only to instantiate your service model and fire up the service's main thread. If the building process for the services model is to convoluted it might also take too long. In that...
13 Dec 2010 by jollyabhi
hi allPlease tell me asap....How to open Windows Form from a windows Service???Regards..