windows - Windows 服务项目中的 AppData\Roaming 文件夹

标签 windows windows-services

我需要有关在 Windows 服务程序中获取特殊文件夹的帮助。我在我的 Windows 窗体 应用程序中使用了这段代码:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

并得到路径,""C:\Users\\AppData\Roaming"*

但如果我在我的 Winows 服务 项目中运行相同的代码,我得到的路径是:"C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\"

但我需要更早的路径(进入Windows 窗体)。我如何在服务项目中也获得相同的路径。

我在 “C:\Users\\AppData\Roaming” 文件夹中有用户设置文件、日志和配置文件。因此,我必须在我的 Windows 窗体 应用程序和 Windows 服务 项目中引用相同的路径。

有人可以告诉我,这里有什么区别,我如何在两种类型的项目中获得相同的路径?

谢谢, 沙拉

最佳答案

您的 Windows 服务应使用“用户”帐户,而不是“LocalService”或“LocalSystem”。

        ServiceProcessInstaller process = new ServiceProcessInstaller();
        process.Account = ServiceAccount.User;

并且在安装服务的过程中,您需要指定当前登录用户的用户名和密码。用户名应采用以下格式:“MachineName\UserName”。示例:“.\John”

关于windows - Windows 服务项目中的 AppData\Roaming 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8273674/

相关文章:

c# - COM 组件在控制台应用程序中可以 100% 工作,但从服务调用时会失败

windows - 避免从锁定构建目录的东西中彻底失败(并因此构建)

php - 如何让 shell_exec 在 IIS 6.0 上运行

windows-services - WIX ServiceInstall - 将服务设置为在 NetworkService 帐户下运行

c# - 检查电子邮件的 Windows 服务 - IIS/C#

c# - 将线程应用程序转换为服务

c# - 在 C# 的文件夹中查找最新创建的文件的好方法是什么?

java - CPU 未列为使用 Windows 的设备

windows - Azure 无法停止 VM

windows-services - 如何从指定名称和描述的命令行安装 Windows 服务?