Announcement

Collapse
No announcement yet.

find reg key string and do a specific action

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • find reg key string and do a specific action

    Hi,

    could someone help me out with something i'd like to do perhaps?

    i'd like a batch scrip to find a specific key in registry and if that one exists import specific additional entries.

    ie.
    if this reg key exists: HKEY_CURRENT_USER\Software\Autodesk\DWG TrueView\R12\
    then i'd like to import: DWG TrueView 2014 (ConversionSetUp).reg

    I guess I need to use some: for /f (with tokens?) but i'm not really into how to exactly use that :'(
    I know I can search the registry with reg.exe QUERY and probably need to use findstr (or just find?) with it to get the key i'm looking for...

    and when it's found I can import the custom "DWG TrueView 2014 (ConversionSetUp).reg" with REGEDIT -s "DWG TrueView 2014 (ConversionSetUp).reg" or take the complete .reg file and put it in the batch and use ie. reg add "HKEY_etc" /v name /t REG_SZ /d value /f

    (if not found do nothing or go to :EOF or :exit)

  • #2
    Re: find reg key string and do a specific action

    Do not use regedit.exe to merge from a reg file, UAC has problems with it. Use Reg.exe IMPORT instead.

    You can use && ("followed by an action to do when there was no error") and || ("followed by an action to do when there was an error returned") as showed in the sample below,
    Code:
    @echo off
    
    Reg.exe QUERY "HKCU\Software\Autodesk\DWG TrueView\R12" 2>nul &&(
       echo.Do registry import...) ||(echo.Reg key does not exist & goto:next1)
    
    Reg.exe IMPORT "DWG TrueView 2014 (ConversionSetUp).reg"
    :next1
    
    
    Pause
    personally I would prefer adding statements like reg.exe add "HKEY_etc" /v name /t REG_SZ /d value /f in the batch rather than using an additional separate file (.reg file).

    /Rems
    Last edited by Rems; 6th June 2013, 17:54.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: find reg key string and do a specific action

      works like a charm, thank you very much...

      Comment

      Working...
      X