Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to log who started or stopped a windows service?

I have some windows services written in C#. When somebody stops or starts the service, I would like to be able to determine who it was and log that information.

I tried logging Environment.UserName but that evaluates to SYSTEM even on my local machine.

Also, for the time being these services are running on Windows 2000 server.

like image 992
HitLikeAHammer Avatar asked Jan 30 '09 18:01

HitLikeAHammer


People also ask

How do I know who stopped a service in Event Viewer?

Save this answer. Show activity on this post. In Event Viewer, look in the "Windows Logs"->"System" event log, and filter for Source "Service Control Manager" and Event ID 7040. Find the event saying "The start type of the service was changed from original start type to disabled" for the service you're interested in.

What is the event ID for service stopped?

The event is logged at boot time noting that the Event Log service was stopped.

Does Windows have a system log?

System Log: Windows system event log contains events related to the system and its components. Failure to load the boot-start driver is an example of a system-level event. Application Log: Events related to a software or an application hosted on a Windows computer get logged under the application event log.


2 Answers

Within the Event Viewer (Control Panel | Administrative Tools | Event Viewer) on the System tab the Service Control Manager logs who started and stop each event. I've just tested this myself and viewed the results. This leads me to two things:

  1. You may be able to query or hook those events from the Service Control Manager as they happen, or
  2. You can definitely just query the Event Viewer's "System" log to look for those events for your Service.

Hope that leads you to your solution.

like image 80
JMD Avatar answered Oct 23 '22 22:10

JMD


  • You can filter the System EventLog by Service Control Manager enter image description here

Event ID 7040 - covers Service start type change (eg disabled, manual, automatic)

Event ID 7036 - covers Service start/stop

enter image description here

For others that have PowerShell, you can use this:

get-eventlog -source "Service Control manager" -LogName System | select message, timegenerated, username | Out-GridView

enter image description here

like image 9
KERR Avatar answered Oct 23 '22 21:10

KERR