windows-services

How to call a windows service from asp.net

If I create a Windows Service, is there a way to call that service from asp.net? ...

Querying a Windows Service over a Network

I have written a windows service in C# that gathers performance, disk and memory information and writes it to the EventLog. It is enabled as a network service. What I would like to do is be able to gather this information from a remote location. This service will run at various client machines and I would like to retrieve this informatio...

Windows will not shutdown programmatically when logged off

I have an application that is launched from within a service using a local administrator account. This application is accessible by a web browser and the host PC can be shut down through this interface. If a user is logged into the host PC and I browse to it and shut it down, the application exits and shuts down the PC as I would expect...

C# Windows EventLog EntryWritten Handler

I have the following code in both a C# console app and a C# windows service. It works in the console app. It picks up the specified event, and calls MatchEvent() correctly. The same code in a C# windows service does not pick up the same specified event, it never sees it, but sees the other events. The event in question is written to the ...

What is the best way to call/start a Windows Service every x seconds?

I have a Windows Service which is basically accessing a mailbox and reading the emails. I am trying to figure out the best way to check the mailbox every x seconds. One method is to just call Thread.Sleep, then call the Start Method again, e.g. protected override void OnStart(string[] args) { // get config settings CheckMailb...

Location of a Windows service *not* in my project

If I right-click and choose Properties on a service (like, say, Plug and Play) in the Services dialog, I get several pieces of information, including "Path to executable". For Plug and Play (in Vista) this is: C:\Windows\system32\svchost.exe -k DcomLaunch Is there some way I can get this same piece of information using .NET code if I ...

Use ServiceController to start a service with a different account

I'm using the ServiceController class to start a (custom) installed service, like this: var newServiceController = new ServiceController("theNameOfMyService"); newServiceController.Start(); Trouble is, the service always runs under the local system account, and instead I want it to run under my account. Can anyone tell me how to use ...

Killing a windows session from a Java program

I am running a tomcat server and am attempting to update code on that server. To do this I need to shut down the server reliably in a Windows environment. To the best of my knowledge, the tomcat shutdown.bat script can have issues with runaway threads, and I need this to work even if I accidentally create a thread that will keep the .b...

What directory does a Windows Service run in?

I've created a very simple .NET Windows Service and installed it using InstallUtil.exe utility. In the service I have a piece of code as such: if (File.Exists("test_file.txt")) { // Do something clever } I've created a file called test_file.txt in the same directory as the service but the commented part of the code is never being ...

Why does my Windows Service logs not show up in the Application Event Log?

I've created a run of the mill C# Windows Service using the windows service project template. I've been able to install it correctly, and start and stop it without any issues. However, when I go to my event viewer to see the log of it starting and stopping, I get nothing. Here's the sample code I'm testing: public MyService() { ...

Batch programming, stop and start services

It is save to terminate the services using taskkill when the attempt to stop using NET STOP was failed? And if i terminate it using taskkill, do NET START command will affect or do i need to use START command? consider this code as example: @ECHO OFF :STOP NET STOP someservices IF ERRORLEVEL == 0 GOTO :START GOTO :KILL :START NET STA...

Windows service writing files to network share

I have a windows service running which moves files from a watched folder (IO.FileSystemWacher) to a UNC share on a network. The network share is secured, but the share has full control for the Service user; despite this I get problems with the file path not being found. I intend to impersonate the service (current) user, but am not su...

How to stop a service within the OnStart method?

I'm writing a windows service in .net 2.0. What should I do within the OnStart method if for some reason I don't want it to start? Can I simply call the Stop() method of the base class (ServiceBase)? I've tried that and am getting some funny memory access exceptions. Is it required to start a separate thread to call the Stop() method? ...

Can users interact with services directly on Microsoft Vista?

From the Microsoft website (see msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx) it clearly says "Services cannot directly interact with a user as of Windows Vista". So I decided to test this by using "psexec -s cmd.exe". As far as I know, "psexec" creates a service in order to open a command prompt. Needless to say it worked. I ...

Windows Service restarts on Exception

I'm building a windows service that grabs information from a website periodically How can I start looking again when a exception is caught? for example when internet goes down and up later. Code: public string cadena(string pagina) { try { String cadena; WebRequest myWebR...

Windows Listener Service

How do I write a windows service in c# that listens for tcp connections and processes these connections? The problem is that I want a better method than to "block" in the main thread e.g. while(true) ; I can start the listener on another thread but the main thread needs to block to prevent the application from exiting (and the ser...

How to kill process started by a service on Windows 2000 Server?

I need to kill a process on a Windows 2000 production server, which was started by a windows service. However, doing that from the GUI just gives me "Access denied", so now I am considering to create a small application or script to do it. I only have occasionally access to the GUI, I do not have usernames, passwords etc. for the server....

Trigger that inserts into linked table causing an error

I'm having an issue with a trigger that inserts a value into the same tabled on a linked server. Here is the trigger in question ... USE [localDB] GO /****** Object: Trigger [dbo].[INS_New_Row] Script Date: 05/26/2009 10:50:56 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -...

.NET Webservice half works, half 404's

I have a .NET webservice running as a windows service on a Windows Server2003 R2 computer. I have a separate .NET/C# 2.0 app running that calls this webservice from elsewhere on our LAN. The webservice has 2 methods - 1 of these method calls works flawlessly. However, the other method always returns a 404 "not found" error. I can vis...

How to run c# application with admin creds?

I wrote a c# application that unlocks users when they are locked out of their account (Active Directory). The application searches for users in a specific OU and will list the locked out users in a combobox. Then you selected that user from the combobox and choose unlock. If you are logged in as an admin it works perfect. If you are a n...