Windows 7: Redirecionar pasta do PowerShell?

0

Existe uma maneira de redirecionar uma pasta usando o PowerShell no Windows 7? Pontos de bônus por poder fazer isso como administrador de outra conta.

Para ser muito claro, o que quero fazer é isso . Eu não quero mudar o diretório de trabalho PS, mover uma pasta para algum lugar ou criar um atalho / junção / link simbólico / hardlink (ou seja, todas as coisas que eu poderia encontrar soluções para em SU / SE). Apenas para evitar mal-entendidos; Eu sei que isso é uma característica bem obscura. :)

Obrigado!

    
por Silanea 22.02.2016 / 13:06

1 resposta

0

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:

por 23.02.2016 / 02:06