获取当前用户%APPDATA%路径而不是管理员 [英] Obtain Current Users %APPDATA% Path and not Admins

查看:86
本文介绍了获取当前用户%APPDATA%路径而不是管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找当前用户%APPDATA%文件夹的路径.

I am looking to get the path to the current users %APPDATA% folder.

注意:如果您使用 RequestExecutionLevel admin 然后使用 $ APPDATA 将指向admins漫游文件夹,而不是当前用户的应用程序数据文件夹.

Note: I am aware of the variable $APPDATA BUT if you run your installer with RequestExecutionLevel admin then $APPDATA will point to the admins roaming folder and NOT the current user's app data folder.

我需要找出当前用户的%APPDATA%路径,以便可以将文件写入其漫游目录.有人知道我怎么能找到这个吗?

I need to find out the current users %APPDATA% path so I can write files to their roaming directory. Does anyone know how I can find this out?

RequestExecutionLevel  admin

Section "Main"
    MessageBox MB_OK "AppData is: $APPDATA" # knowtice that its the path to the admins folder not the current user's
SectionEnd

推荐答案

当前用户"一词含糊不清,您是说:

The term "Current User" is ambiguous, do you mean:

  • 您从 WTSQueryUserToken()获得的用户?(WinLogon)
  • 运行外壳程序任务栏的用户?( GetShellWindow())
  • 启动设置过程的用户(父过程)?
  • The user you get from WTSQueryUserToken()? (WinLogon)
  • The user that the shell's taskbar is running as? (GetShellWindow())
  • The user (parent process) that started your setup process?

如果您对Runas感兴趣,所有这些用户都可以成为不同的用户!

All of those can be different users if you are having fun with runas!

来自 Harry Johnston 的评论继续,一旦您开始混合%ProgramFiles%和%AppData%和/或HKLM和HKCU,您的设置在多用户方案中就被破坏了.当其他用户启动应用程序时会发生什么?他们不会在您的%AppData%中保存您的文件.

The comment from Harry Johnston is spot on and once you start mixing %ProgramFiles% and %AppData% and/or HKLM and HKCU your setup is broken in multi-user scenarios. What happens when a different user starts the application? They are not going to have your files in their %AppData%.

如果外接程序已在全局位置安装/注册,则可以将AppData模板"文件安装在%ProgramFiles%,%CommonProgramFiles%或%ALLUSERSPROFILE%中,并且当您第一次以特定用户的身份运行外接程序时,文件到%AppData%.

If the addin is installed/registered in a global location you can install the AppData "template" files in %ProgramFiles%, %CommonProgramFiles% or %ALLUSERSPROFILE% and when your addin runs as a specific user for the first time you copy the files to %AppData%.

活动设置可以使用作为替代方案,但可能需要注销/登录周期.

Active Setup could be used as a alternative but it will probably require a log-off/log-on cycle.

如果由于某种原因无法实施延迟的复制/安装,您将遇到 UAC插件之类的黑客.使您可以访问启动安装程序的用户...

If you cannot implement the delayed copy/install for some reason you are left with hacks like the UAC plugin which gives you some access to the user that started your installer...

这篇关于获取当前用户%APPDATA%路径而不是管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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