访问当前记录的用户下载文件夹中的文件夹中的C#Windows服务中的文件夹

发布于 2025-01-25 17:54:38 字数 237 浏览 3 评论 0原文

我有使用service.msc使用C#部署的Windows服务,

我想访问登录的当前用户下载文件夹

:如果当前登录的用户名是管理员,那么我想访问

c:\ users \ admin \ admin \ downloads

and downloads and downloads和如果当前登录的用户名是tomas,那么我想添加

C:\ users \ tomas \ downloads。

i have windows service which is deployed using service.msc using c#,

i want to access the current logged in users download folder

eg: if the current logged in username is admin, then i want to access

C:\Users\admin\Downloads

and if the current logged in username is tomas, then i want to acess

C:\Users\tomas\Downloads.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若水微香 2025-02-01 17:54:39

您可以使用shgetnoichfolderpath(folderID_Downloads),以所需用户帐户的令牌传递。诀窍将在于知道您想要哪个用户。可能有多个用户同时登录。可能根本没有登录的用户。如果您的服务在系统帐户下运行,则可以通过wtsenumerateessions()列举活动用户会话,并通过wtsqueryusertoken()获得其用户令牌。

You can use SHGetKnownFolderPath(FOLDERID_Downloads), passing in a token for the desired user account. The trick will be in knowing which user you want. There may be more than one user logged in at the same time. There may be no users logged in at all. If your service is running under the SYSTEM account, it can enumerate active user sessions via WTSEnumerateSessions() and get their user token via WTSQueryUserToken().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文