How to run the .reg file using PowerShell?

ぐ巨炮叔叔 提交于 2019-12-05 21:06:49

How about using reg.exe instead of regedit.exe

Get-Command reg

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     reg.exe                                            10.0.16... C:\Windows\system32\reg.exe

this worked for me fine:

reg import .\test.reg

You may be trying to run it with insufficient privileges. This snippet should work:

$startprocessParams = @{
    FilePath     = "$Env:SystemRoot\REGEDIT.exe"
    ArgumentList = '/s', 'C:\file.reg'
    Verb         = 'RunAs'
    PassThru     = $true
    Wait         = $true
}
$proc = Start-Process @startprocessParams

if ($proc.ExitCode -eq 0) {
    'Success!'
}
else {
    "Fail! Exit code: $($Proc.ExitCode)"
}

Pause

I use

Invoke-Command {reg import \\server\share\test.reg *>&1 | Out-Null}

the last part

*>&1 | Out-Null

pipes the output to null so the console doesn't see it. I do not think this is required but it annoyed me.

This is what I use

regedit /s "c:\file.reg"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!