I'm very new to .Net, C# and Visual Studio. Now I want to develop a Windows Service application using C#. The Windows Service needs to write some data to some file. I'm using Visual Studio 2010. I'm using Windows XP as my operating system. I created a windows service.its installer etc.
When I install the Windows Service in the folder other than non-default folder (other than C drive), after running service it will create the file and write the text file success.
When I install the service in the default location (that when the time of installation the i cannot the default path) (please refer the attached image)
Then after installing then I run the service. But the file is not created and there is no exception thrown. The following are the codding snippet for file.
string logPath = AppDomain.CurrentDomain.BaseDirectory + "log\CastrolSdWindowsService_Log.txt";
fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
I cannot find why the file is not created in C drive.
You can chose between (as wrote above) either change path to log files and move them outside protected program file folder, or you can change NTFS permissions to allow WRITE/MODIFY on those log files and folders that you want to write inside "program file/your app" folder.
Note, that your windows service application did not run as SYSTEM. it may be NT AUTHORITY\LOCAL SERVICE or NT AUTHORITY\NETWORK SERVICE Run your service then run process explorer, switch on column "USER" and check it.