c# 服务:如何获取用户配置文件文件夹路径 [英] c# service: how to get user profile folder path

查看:68
本文介绍了c# 服务:如何获取用户配置文件文件夹路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 C# windows 服务中获取用户目录...
...像 C:\Users\myusername\
理想情况下,我想要漫游路径...
...像 C:\Users\myusername\AppData\Roaming\
当我在控制台程序中使用以下内容时,我得到了正确的用户目录...

I need to get the user directory from within a C# windows service...
...like C:\Users\myusername\
Ideally, I'd like to have the roaming path...
...like C:\Users\myusername\AppData\Roaming\
When I used the following in a console program I got the correct user directory...

System.Environment.GetEnvironmentVariable("USERPROFILE"); 

...但是当我在服务中使用相同的变量时,我得到...
C:\WINDOWS\system32\config\systemprofile
如何从服务中获取用户文件夹甚至漫游文件夹位置?
提前致谢.

...but when I use that same variable in a service, I get...
C:\WINDOWS\system32\config\systemprofile
How can I get the user folder and maybe even the roaming folder location from a service?
Thanks in advance.

推荐答案

服务不会像用户一样登录,除非该服务被配置为使用特定用户的配置文件.所以它不会指向用户"文件夹.

A service doesn't log on like a user, unless the service is configured to use a specific user's profile. So it's not going to point to "user" folders.

这篇关于c# 服务:如何获取用户配置文件文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆