c# - Relative path not working in windows service -
i have bit weird situation. in onstart method of windows service if put following code:
file.appendalltext(appdomain.currentdomain.basedirectory + "\\testfile.txt", "started " + appdomain.currentdomain.basedirectory); it works , inside text file stored:
started c:\users\guser\documents\visual studio 2012\projects\freespacecontrolservice\freespacecontrolservice\bin\debug\ the text file created inside debug directory.
but if use such code instead of above(at same place):
file.appendalltext("testfile.txt", "started"); the text file is not created in same directory above. why not created in same directory? (it seems created in windows/system32 check - there 2 executables? why did first return debug directory?)
and typically(in path) store settings windows service , logs?
because working directory of windows services %windir%\system32.
you can verify yourself:
file.appendalltext(appdomain.currentdomain.basedirectory + "\\testfile.txt", "my working directory is: " + directory.getcurrentdirectory()); and typically(in path) store settings windows service , logs?
- settings: in windows registry.
- logs: in windows event log.
- any other files service might need: somewhere below
system.environment.specialfolder.commonapplicationdata(e.g.c:\programdata\myservice). more details, see following question:
what significance of programdata folder in windows?.
Comments
Post a Comment