C# Windows Service start error 1064 Directory not found when changing working directory

  • Thread starter Thread starter Ray Zorg
  • Start date Start date
R

Ray Zorg

Guest
Hi,

I'm running into a little behavior that I cannot explain. I've build a C# Service that watches the Security EventLog for specific events and generates a little report based on them.

The application runs on a Windows 2008 R2 Standard Server with .NET 4.8 installed. The target framework is .NET 4.7.2 and the service runs as Local System.

So far the application works like a charm but... in the wrong folder and I seem unable to change it. The default folder is "C:\Windows\SysWow64\", normal for a 32-bits service. But I'd like to point it to another folder "C:\TestApps\EventLogGuard" as a working directory.

I've tried to change the working directory or path it writes files to in two ways (both resulting in the same error):

1. By changing the working directory

string path = @"C:\TestApps\EventLogGuard";
Directory.SetCurrentDirectory(path);

2. By changing the path I'm writing to in a streamwriter to:


string fileName = @"C:\TestApps\EventLogGuard\IPList.txt";
string fileLog = @"C:\TestApps\EventLogGuard\EventLogGuard.log";

using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName))
{

~~~~~~

}




As soon as either option is added I'm getting an error 1064 on-start. In the Windows EventLog I can see the following error displayed:

Problem signature:
P1: EventLogGuardSVC.exe
P2: 1.0.0.0
P3: f8080359
P4: mscorlib
P5: 4.8.3761.0
P6: 5c9c6e98
P7: 168e
P8: fc
P9: System.IO.DirectoryNotFound
P10:

Does anyone have an idea what may be causing this behavior or experienced something similar?

Edit: The directory exists and I do have a check added if the path exists as well, makes no difference.

Continue reading...
 
Back
Top