访问当前记录的用户下载文件夹中的文件夹中的C#Windows服务中的文件夹
我有使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
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 viaWTSEnumerateSessions()
and get their user token viaWTSQueryUserToken()
.