开发者

Finding users' HOMEPATHs from a service

开发者 https://www.devze.com 2023-04-03 06:15 出处:网络
In the process of writing a service I have //# Service Account Information serviceProcessInstaller.Account = ServiceAccount.LocalSystem;

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 servi开发者_开发百科ce 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号