Change another user’s records with powershell credential

Asked

Viewed 36 times

0

Someone knows how to change a record having the credential created. I need to change a value inside HKEY_CURRENT_USER but another user, I saw that cmdlets Set-Item has the -Credential parameter, but I can’t use it, it displays the following error: Set-Item : Unable to retrieve dynamic parameters for cmdlet. The provider does not support the use of credentials. Run the operation again without specifying credentials.

1 answer

0

  1. You did not put the command code line Set-Item.

  2. The parameter Credential is used to execute a command as if it were in another account. You could only access the branch HKEY_CURRENT_USER if you knew the password for this account. I believe this is not your reality.

  3. In the context of your doubt, it is wrong to speak in credential created. Probably what you meant is profile created.

  4. Starting from the premise that one wants to change some information in the branch HKEY_CURRENT_USER of a profile created, being in a third party account, this would only be possible if the account executing the command has administrative powers in the operating system.

  5. The steps to change the record of a created profile that is not loaded are not trivial. For example, there is no native command in powershell to load and download a log branch. The external command "reg.exe" needs to be used.

##  Inicializa variáveis gerais
$EditorDeRegistro = [Environment]::GetFolderPath('System') + '\reg.exe'
$ArquivoDeRamificaçãoDoPerfil = 'D:\Usuários\João Ninguém\ntuser.dat'
$AcessoAoPerfil = 'Acesso'
Push-Location -LiteralPath ( Get-Location )

##  Libera memória
[GC]::Collect()
[GC]::WaitForPendingFinalizers()

##  Carrega perfil
$ParâmetroSimplificado = @{
    FilePath = $EditorDeRegistro
    ArgumentList = 'LOAD', "HKU\$AcessoAoPerfil", """$ArquivoDeRamificaçãoDoPerfil"""
    Wait = $true
    WindowStyle = 'Hidden'
    PassThru = $true
}
$CódigoDeSaída = Start-Process @ParâmetroSimplificado
$CódigoDeSaída

##  Vai para a ramificação do perfil carregado
Set-Location -LiteralPath "Registry::HKEY_USERS\$AcessoAoPerfil"

##  Execute os comandos que quiser, desde que LiteralPath ou Path comece com '.\'
Set-ItemProperty -LiteralPath '.\Environment\' -Name 'teste de variável de ambiente' -Value 'teste de associação para variável de ambiente'

##  Descarrega perfil
$ParâmetroSimplificado.ArgumentList = 'UNLOAD', "HKU\$AcessoAoPerfil"
$CódigoDeSaída = Start-Process @ParâmetroSimplificado
$CódigoDeSaída

##  Libera memória
[GC]::Collect()
[GC]::WaitForPendingFinalizers()

##  Retorna à pasta inicial
Pop-Location
  1. I use this solution in powershell 2.0 (Windows 7) and powershell 5.1 (Windows 10).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.