通过在本地配置文件下运行服务从 Windows 服务获取用户 appdata 路径 [英] Get user appdata path from windows service by running service under local profile

查看:24
本文介绍了通过在本地配置文件下运行服务从 Windows 服务获取用户 appdata 路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Windows 应用程序.因为我已经使用环境变量检索了 appdata.所以它给了我以下路径

I have a windows application. In that i have retrieved appdata using environment variable. So it gives me following path

c:\文档和设置\当前用户名\应用程序数据.

c:\document and settings\current user name\application data.

但是当我使用环境变量从 Windows 服务中检索 appdata 路径时,我得到以下路径

But when I retrieve the appdata path from windows service using environment variable i get following path

c:\windows\ServiceProfiles\LocalService\AppData\Local

c:\windows\ServiceProfiles\LocalService\AppData\Local

所以这个 appdata 路径不同于我从 windows 应用程序环境变量 appdata 路径获得的 appdata 路径.

so this appdata path is different from appdata path that i got from windows application environments variable appdata path.

我在本地配置文件下运行 Windows 服务.我知道,如果我将服务配置文件更改为在用户下运行,则服务 appdata 路径和 Windows 应用程序 appdata 路径匹配,但服务提示输入用户名和密码.

I m running windows service under local profile. I know that if i change service profile to run under user then service appdata path and windows application appdata path matches but service prompts for username and password.

所以我的问题是如何通过在本地配置文件下运行服务而不提示输入用户名和密码来从服务中获取用户 appdata 路径?

so my question is how to get user appdata path from service by running service under local profile without prompting for username and password?

推荐答案

我也遇到过那个问题,看了你的问题,第一眼没找到答案.

I have also encountered in that problem and looked at your question but i at first sight didnot find an answer in it.

这是莫希特国王的答案

我发现无法通过在配置文件LocalSystem"下运行服务来从 Windows 服务获取用户 appdata 路径.所以我使用了 Environment.SpecialFolder.CommomAppData,它在 Windows 上运行时为我提供了应用程序数据路径 C:\ProgramData7,当在 Windows 服务中使用相同的东西时,它也给出了相同的路径,我也在配置文件LocalSystem"下运行该服务,所以它没有提示我输入凭据.所以这解决了我的问题."

"I found out that is not possible to get user appdata path from windows service by running service under profile "LocalSystem". So I used Environment.SpecialFolder.CommomAppData which gives me app data path C:\ProgramData when run on windows 7 and when used same thing in windows service, it also gived the same path and i also ran the service under profile "LocalSystem" so it did not prompt me for credentials. So this solved my problem."

@Mohit Shah 请将此标记为答案,以便其他人可以从中获得帮助.

@Mohit Shah Please mark this is as answer so that other can take help from that.

这篇关于通过在本地配置文件下运行服务从 Windows 服务获取用户 appdata 路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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