简体   繁体   中英

Running as administrator: access user VirtualStore

I have an issue with my software installation / first time run on Vista / 7 in relation to the VirtualStore.

My software is written in C#. Installer: NSIS.

  1. My application is installed using NSIS. It runs as administrator
  2. After installation is finished, the user can immediately start the software from the installer.
  3. This results in the first run of the program to be executed as admin.
  4. During the first run, a wizard has to be completed. This wizard will import data from an older version of the software, that is already on the computer (C:\\Program Files\\OldProgram\\Data)
  5. However, on 7/Vista, this data is in the VirtualStore of the user. When I'm admin, I don't "see" this data and I can't convert it.

Questions:

  1. Can I know which user is currently logged in?
  2. Is there a generic way to access the Virtual Store of this user? Taking into account that the "Program Files" folder is named different is some countries and on 64-bits my app sits in "Program Files (x86)".
  1. UserInfo::GetName will give you the username, use UserMgr if you need more control
  2. Windows does not really provide a way to access another users special folders without their token, but this helper macro works in most cases. The name/location of the virtual store is not documented AFAIK so you have to get the closest special folder with GetUserShellFolderFromRegistry and then hardcode the VirtualStore part of the path...

If you want to launch a program as the user and not the administrator performing the install, use the UAC plugin (Or just remove the run checkbox on the finish page and let the user start the program normally)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM