1

In the process of writing a service I have

        //# Service Account Information
        serviceProcessInstaller.Account = ServiceAccount.LocalSystem;

in the installer for it.

I was having problems writing a log to

    static string USERS_HOME_DIR = Environment.GetEnvironmentVariable("HOMEDRIVE") + Environment.GetEnvironmentVariable("HOMEPATH");

since when the service was running (installed "as administrator") the event logger was reporting

Service cannot be started. System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Documents\Folder of Interest'

I need the HOMEPATHs of the users of the local_PC, any ideas how to get them?

UPDATE

Actually it would be better to just get the path for the currently logged on user, as their session and the service start. My sevice is not re-entrant but one user is better than none.

John
  • 6,433
  • 7
  • 47
  • 82
  • possible duplicate of [Getting logged-on username from a service](http://stackoverflow.com/questions/5238133/getting-logged-on-username-from-a-service) – Sebastian Mach Sep 08 '11 at 08:57
  • @phresnel I'd rather iterate all users' homepaths than use unmanaged dll's. – John Sep 08 '11 at 09:04
  • I'm also happy for it to start once and only once when the first user logs in and to use their homepath. – John Sep 08 '11 at 09:10

1 Answers1

1

If I understand your question correctly what you're looking for are the special folder enumerations.

With something like:

String PersonalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

If you want to run the service as the localsystem account there's a separate set of standards for storing the data. See this answer on serverfault.

Community
  • 1
  • 1
Timbo
  • 4,505
  • 2
  • 26
  • 29
  • Yes, that's what I asked, though I'm not sure it is responsible for the non-starter error I get logged. – John Sep 08 '11 at 09:18
  • Understood - I've updated my answer, again, a little tenuous but I think I'm answering the question! :) – Timbo Sep 08 '11 at 09:30
  • I'm liking this answer more and more after a stack trace in the Computer Management 'console' - if console is the right term? – John Sep 08 '11 at 09:45
  • I think I need an autorun.exe architecture. – John Sep 08 '11 at 10:09