26

I want to run the .reg file (registry file) using PowerShell Script but I am not able to run it. When i run it manually it creates the respective nodes in registry but i want it execute using powershell script. Below is the code which i tried using but got no results -

$PathofRegFile="c:\file.reg"
regedit /s $PathofRegFile

Another code which i tried was this -

Start-Process -filepath "C:\windows\regedit.exe" -argumentlist "/s c:\file.reg"

Please Help..!

Below is the Content of my .reg file

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\SePI]

[HKEY_LOCAL_MACHINE\SOFTWARE\SePI\STEP]
@=""

[HKEY_LOCAL_MACHINE\SOFTWARE\SePI\STEP\Platform]
"VERSION"="8.2.6.0"

[HKEY_LOCAL_MACHINE\SOFTWARE\SePI\STEP\Platform\AppService]
"MONITORINTERVAL"=dword:00000005
"MONITORAPPS"="STEP Audit"

[HKEY_LOCAL_MACHINE\SOFTWARE\SePI\STEP\Platform\Audit]
"TRACEON"=dword:00000000
"TRACEDIR"="Specifies the directory to dump trace files if TRACEON is set to 1"

[HKEY_LOCAL_MACHINE\SOFTWARE\SePI\STEP\Platform\Common]
"SSMITRACEFILEX"="C:\\Program Files\\SePI\\STEP\\LogFiles\\SSMITraceFile.txt"
"SSMILOGERRORSLOCALLY"="Yes"
"SSMIDoNotSendToAudit"="FALSE"
"ResourceFile"="C:\\Program Files\\SePI\\STEP\\Programs\\"
"REPORTALLEXCEPTIONS"="Yes"
"KSPath"="C:\\Program Files\\SePI\\STEP\\KeyStore\\"
"KEY"="10069356713705F858B56A9E850DD8CB7D"
"intelliSUITEnode"="WebApp"
"InstallationDir"="C:\\Program Files\\SePI\\STEP\\"
"IMSFirstRun"=dword:00000001
"CONFIGPATH"="C:\\Program Files\\SePI\\STEP\\Configuration Files\\"
"COM_VERBOSEGLOBALCACHE"="False"
"COM_UserProfileCacheExpirationInSecs"="30"
"COM_SSMISenderUtilCacheExpirationInSecs"="120"
"COM_REPORTIGNOREDEXCEPTIONSASWARNINGS"="True"
"COM_LOCALUTILSCACHEEXPIRATIONINSECS"="600"
"COM_DEFAULTPROPERTYCACHEEXPIRATIONINSECS"="600"
"ProductName"="Ron"

[HKEY_LOCAL_MACHINE\SOFTWARE\SePI\STEP\Platform\ESI]

[HKEY_LOCAL_MACHINE\SOFTWARE\SePI\STEP\Platform\ESI\ITranQueryPrep]
"PATH"="C:\\Program Files\\SePI\\STEP\\QueryTemplates"

[HKEY_LOCAL_MACHINE\SOFTWARE\SePI\STEP\Platform\ITran]
"MAXROWSTORETURN"=dword:000003e8
"WRITERPSWD"="PASSWORD"
"WRITER"="ITRAN_WRITER"
"SERVER"="SQL SERVER"
"READERPSWD"="PASSWORD"
"READER"="ITRAN_READER"
"DBNAME"="DATABASENAME"

[HKEY_LOCAL_MACHINE\SOFTWARE\SePI\STEP\Platform\ReportingSvc]
"STATUSINTERVAL"="5"
"POLLINTERVAL"="2"
"MONITORINTERVAL"="5"
"MAXWORKERTHREADS"="5"
"CONFIGFILE"="C:\\Program Files\\SePI\\STEP\\Configuration Files\\"
SRP
  • 999
  • 4
  • 21
  • 39

5 Answers5

42

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
  • 2
    .\ refers to current folder, in your case you should use absolute path so the command would be "reg import C:\file.reg" – Aurimas Stands with Ukraine Apr 05 '18 at 16:32
  • 2
    @ Aurimas N, I tried using it in this way- reg import C:\Demo.reg It worked and in registry it created the node but on Command Shell it gave this message in RED colour - reg : The operation completed successfully. At C:\Suraj\AutoServerRoleScript.ps1:77 char:1 + reg import C:\Demo.reg + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (The operation completed successfully.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError – SRP Apr 06 '18 at 05:02
  • 4
    it seems that RED message is only happening in ISE, you may try `start-process reg -ArgumentList "import C:\Demo.reg"` – Aurimas Stands with Ukraine Apr 06 '18 at 06:48
  • I keep receiving this error: reg : ERROR: Error opening the file. There may be a disk or file system error. At line:1 char:1 + reg import "~\AppData\Local\WinDynamicDesktop\scripts\MouseScript\Dar ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (ERROR: Error op...e system error.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError – Eyal Cohen Feb 17 '23 at 12:40
  • maybe there is an actual problem with the disk, try running `chkdsk c: /f` to see if there are any problems reported – Aurimas Stands with Ukraine Feb 18 '23 at 11:28
9

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.

Drake
  • 93
  • 1
  • 3
7

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
Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
3

You can use this :

Start-Process -filepath "$env:windir\regedit.exe" -Argumentlist @("/s", "`"C:\file.reg`"")
GP007
  • 31
  • 1
0

This is what I use

regedit /s "c:\file.reg"

Johan A.
  • 378
  • 3
  • 7