0

I have created a Service in C# in which I am performing two tasks.

Task-1: Extracting Windows Event Logs.

Task-2: Sending the desired log (if present) to a Database that reside on another system.

If I run this Service under LocalSystem Account, it successfully performs Task-1 because its System related, but not Task-2 because LocalSystem Account does not have access to Network.

If I run this Service under NetworkService Account to access the Database on other Machine, it does not perform Task-1 because NetworkService Account has Limited access over System resources. Due to this, it is unable to extract Windows Event Logs.

I know that my code is correct because I have tested the whole code in Console Application and it performs both Tasks correctly.

I need the solution through which I can perform both Tasks through a Service.

Faheem
  • 509
  • 2
  • 7
  • 23

1 Answers1

0

"If I run this Service under LocalSystem Account, it successfully performs Task-1 because its System related, but not Task-2 because LocalSystem Account does not have access to Network."

This is not true. The LocalSystem account has access to everything on the system, as far as I know, including the ability to interact with the network. I can speak to this from personal experience because I've had a Windows service in the project I work on for almost a decade now, and it interacts with the network all the time. Check out the accepted answer here for more info.

It's very likely that an exception is occurring when your code is running from the Windows service, but does not occur when running from the Console app. Have you tried debugging your service? Have you checked the Windows event log for errors?

Matt Davis
  • 45,297
  • 16
  • 93
  • 124
  • 1
    Matt, you are right. I was wrong about LocalSystem Account since I am new to Windows Service Programming. However, I have solved the problem by making the WebAPI and the issue is not arising anymore. Thank you. – Faheem May 14 '20 at 18:52