G
Guest
I have a .Net 2.0 Windows service (C#) that runs as system and needs to store
state in files. The files are created and used only by the service. Where
should I store them?
I have tried using
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
but it is giving me inconsistent results. On initial install and start,
GetFolderPath returns the local data directory under the "Local Service"
profile. If I install SQL Server 2005 Express and then restart my service,
the API returns the local data directory under the "Network Service" profile.
If I reboot the system, my service comes up and gets the "Network Service"
profile again, but if I then stop and restart my service, it switches back to
the "Local Service" profile. What gives?
I have replicated this with a simple service generated with VS.Net 2005,
installed with InstallUtil and started with "net start". Here's the code for
my simple service:
const string filename = @"C:\test.txt";
protected override void OnStart(string[] args)
{
if( File.Exists(filename) )
{
File.Delete(filename);
}
using( StreamWriter w = new StreamWriter(filename) )
{
w.WriteLine("Local Data Directory: " +
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
}
}
state in files. The files are created and used only by the service. Where
should I store them?
I have tried using
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
but it is giving me inconsistent results. On initial install and start,
GetFolderPath returns the local data directory under the "Local Service"
profile. If I install SQL Server 2005 Express and then restart my service,
the API returns the local data directory under the "Network Service" profile.
If I reboot the system, my service comes up and gets the "Network Service"
profile again, but if I then stop and restart my service, it switches back to
the "Local Service" profile. What gives?
I have replicated this with a simple service generated with VS.Net 2005,
installed with InstallUtil and started with "net start". Here's the code for
my simple service:
const string filename = @"C:\test.txt";
protected override void OnStart(string[] args)
{
if( File.Exists(filename) )
{
File.Delete(filename);
}
using( StreamWriter w = new StreamWriter(filename) )
{
w.WriteLine("Local Data Directory: " +
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
}
}