Adapting .REG Files.

Page 7 of 13 FirstFirst ... 56789 ... LastLast

  1. Posts : 18,034
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #61

    Matthew Wai said:
    I have added the "PowerShell" line, so that the CMD script will get administrative privileges automatically.
    Code:
    @echo off
    (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b)
    For %%I In ("C:\Implement\*.reg") Do (regedit /s "%%I")
    If %errorlevel%==0 echo. & echo All the .reg files have been merged. 
    pause
    Thank you @Matthew Wai,

    I will give that a try in the morning.

    Do I not need a piece of script to make sure that each reg file has finished processing before going onto the next one, something like -Wait -PassThru as mentioned by @KeithM previously?

    Also, is there anyway to output which reg file is being processed, something like Write-Host "Running Script : " $???

    Thanks in advance.
      My Computer


  2. Posts : 7,631
    Windows 10 Home 20H2
       #62

    Paul Black said:
    to make sure that each reg file has finished processing before going onto the next one
    Code:
    @echo off
    (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b)
    For %%I In ("C:\Implement\*.reg") Do (
    regedit /s "%%I" & if not %errorlevel%==0 echo The file "%%I" could not be merged. & pause)
    If a .reg file cannot be merged, you will see a message, and the process will be paused.

    Paul Black said:
    to output which reg file is being processed
    Code:
    @echo off
    (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b)
    For %%I In ("C:\Implement\*.reg") Do (
    regedit /s "%%I" & echo The file "%%I" is being merged.)
    Pause
      My Computer


  3. Posts : 7,631
    Windows 10 Home 20H2
       #63

    CMD script:
    Code:
    @echo off
    (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b)
    For %%I In ("C:\Implement\*.reg") Do (
    Echo The file "%%I" is going to be merged.
    Regedit /s "%%I"
    If not %errorlevel%==0 echo The file "%%I" could not be merged. & pause)
    Echo Operations completed. & pause
    You may test it on a .reg file that cannot be merged. I don't have such a file.
      My Computer


  4. Posts : 7,631
    Windows 10 Home 20H2
       #64

    I just found that Regedit /s "xxxx.reg" will not output "errorlevel" even if the .reg cannot be merged. In the following example, "Winver.reg" is a .reg file that cannot be merged due to the absence of Windows Registry Editor Version 5.00

    Adapting .REG Files.-errorlevel.jpg
      My Computer


  5. Posts : 18,034
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #65

    Thank you so much for the code @Matthew Wai,
    Matthew Wai said:
    CMD script:
    Code:
    @echo off
    (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b)
    For %%I In ("C:\Implement\*.reg") Do (
    Echo The file "%%I" is going to be merged.
    Regedit /s "%%I"
    If not %errorlevel%==0 echo The file "%%I" could not be merged. & pause)
    Echo Operations completed. & pause
    I tested the .cmd code on a few .reg files before your last post and it didn't throw any out as failing [not merged]. Is there any way round checking for failures that will work?
    I am pretty confident the .reg files are OK because they are mainly from here [TenForums].
    I will try and adapt the code to run .bat files and another one for .ps1 files, maybe something like this for .bat files . . .
    Code:
    @echo off
    Set Folder=C:\ImplementBAT
    (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b)
    For %%i In ("%Folder%\*.bat") Do (
    echo Processing BAT file: "%%i".
    rem If not "%%i" == "%~0" Call "%%i"
    Call /s "%%i"
    If not %errorlevel%==0 echo BAT file: "%%i" could NOT be processed. & pause)
    echo Operations completed. & pause
    Thanks in advance.
    Last edited by Paul Black; 13 Mar 2020 at 10:02.
      My Computer


  6. Posts : 18,034
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #66

    Would I also need a line like . . .
    Code:
    For %%i in ("%Folder%\*.bat") Do Call %%i|| Exit /i 1
    OR:
    Code:
    Start "" cmd.exe
    Code:
    @echo off
    Set Folder=C:\ImplementBAT
    (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b)
    For %%i In ("%Folder%\*.bat") Do (
    echo Processing BAT file: "%%i".
    rem If not "%%i" == "%~0" Call "%%i"
    Call /q "%%i|| Exit /i 1"
    If not %errorlevel%==0 echo BAT file: "%%i" could NOT be processed. & pause)
    echo Operations completed. & pause
      My Computer


  7. Posts : 7,631
    Windows 10 Home 20H2
       #67

    Paul Black said:
    Is there any way round checking for failures that will work?
    Check whether the following will output "errorlevel".
    REG IMPORT FileName.reg
      My Computer


  8. Posts : 18,034
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #68

    Matthew Wai said:
    Check whether the following will output "errorlevel".
    REG IMPORT FileName.reg
    In the cmd prompt it does!
      My Computer


  9. Posts : 7,631
    Windows 10 Home 20H2
       #69

    Note that the following should be used in a CMD script but not in a batch script.
    Code:
    (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b)
      My Computer


  10. Posts : 7,631
    Windows 10 Home 20H2
       #70

    CMD script:
    Code:
    @echo off
    (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b)
    For %%I In ("E:\Testing\*.reg") Do (
    Echo The file "%%I" is going to be merged.
    Reg import "%%I" && echo. || pause)
    I ran the above and got the following:
    Code:
    The file "E:\Testing\System Properties.reg" is going to be merged.
    The operation completed successfully.
    
    The file "E:\Testing\Winver.reg" is going to be merged.
    ERROR: The specified file is not a registry file. You can import only registry files.
    Press any key to continue . . .
    Try it yourself. See for yourself.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 21:31.
Find Us




Windows 10 Forums