Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

c# - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...