Esta definição é controlada pelas chaves Pastas da Shell / Pastas do User Shell :
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
The entries in this subkey can appear in both the Shell Folders subkey and the User Shell Folders and in both HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER. The entries that appear in user User Shell Folders take precedence over those in Shell Folders. The entries that appear in HKEY_CURRENT_USER take precedence over those in HKEY_LOCAL_MACHINE.
Para modificar essas chaves para outra conta, você precisa carregar seção de registro do usuário de destino :
PowerShell will by default expose your HKLM and HKCU hives via drives which work because of the Registry PSProvider.
get-psdrive
get-psprovider
Since we see that it’s the provider that allows us to map these hives we can take it a step further and map a hive from a file (update user hives on a remote system). The problem with this is that the Registry PSProvider doesn’t extend to files. However this doesn’t stop us.
reg load 'HKLM\TempUser' $ntuserlocation
cd hklm:\TempUser
gci
New-PSDrive -Name HKMyUser -PSProvider Registry -Root HKLM\TempUser
cd HKMyUser:\
gci
cd c:
Remove-PSDrive HKMyUser
reg unload hklm\TempUser
This all works great until we attempt to unload that hive file or in some cases the unload works ok but we still have handles to the hive file (you can use sysinternals Handle.exe to see this)
Why is that if we removed the drive and asked Reg.exe to unload the hive? The problem is that the system has not released the memory which still has pointers into that file, preventing us from unloading the hive or stopping us from doing other things.
So what's the trick you ask?
Ask the system to clean up those references that are no longer in use.
[gc]::collect()
This uses the static method Collect from the GC class in .NET which is used for forcing the garbage collector to run and removing those unused references.
Referências:
- Pastas do Shell de usuário
- Windows 7: Registro: diferenças entre Pastas shell e pastas de shell de usuário?
- A longa e triste história da chave Pastas do Shell
- Como vincular novamente as pastas de usuários no Windows 7
- Como redirecionar pastas do shell do usuário para um caminho especificado usando o Profile Maker
- Script Powershell para alterar pastas de perfil de usuário do Windows 7 para locais UNC
- PowerShell: Carregando e Descarregando Hives do Registro