Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Remotely check if registry key exists

    Edited by HansV to replace % with <!t>[%]<!/t> tags, since % followed by a hexadecimal number messes up the display.

    I'm trying to use a BATch file to find if a registry key exists, and populate two lists from there. Here's what I have so far, as well as the proposed usage using a command line utility called PsExec:

    BATch File
    -----------------------------------------
    @echo off
    if exist "HKLMSOFTWAREGoogleGoogle Toolbar" GOTO GOOD
    if not exist "HKLMSOFTWAREGoogleGoogle Toolbar" GOTO BAD
    :GOOD
    echo %computername% >> usmc_nfstranspoupdatesgoogletoobar.txt
    GOTO END
    :BAD
    echo %computername% >> usmc_nfstranspoupdatesnogoogletoolbar.txt
    GOTO END
    :END
    ------------------------------------------

    I know I'm just missing something small, but I don't remember what.

    Usage:

    c:> psexec @c:computers.txt -u admin -c usmc_nfsftranspoupdatesgoogletoolbar.bat

    <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What&#39;s more, you deserve to be hacked." -Richard Clarke

  2. #2
    Silver Lounger
    Join Date
    Apr 2001
    Location
    New York, New York, USA
    Posts
    2,328
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Remotely check if registry key exists

    Consider this thread

  3. #3
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remotely check if registry key exists

    I can't afford a membership to that site to see the answer <img src=/S/groan.gif border=0 alt=groan width=16 height=15>
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What&#39;s more, you deserve to be hacked." -Richard Clarke

  4. #4
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remotely check if registry key exists

    Just scroll down to see the answer, and don't let the site set cookies....

  5. #5
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Remotely check if registry key exists

    IF EXIST determines whether or not a FILE exists. It has nothing whatever to do with registry keys!

    You need REG QUERY "registry key/value" (from a sufficiently-privileged account) and examine what is returned.

    e.g.<pre>@echo off
    :: my PC is named DELLIGHTFUL. Honest.
    reg query "dellightfulhklmsoftwaregooglegoogle toolbar"
    echo errorlevel was %errorlevel%
    reg query "dellightfulhklmsoftwaregigglegiggle toolbar"
    echo errorlevel was %errorlevel%</pre>

    gives
    <pre>! REG.EXE VERSION 3.0

    HKEY_LOCAL_MACHINEsoftwaregooglegoogle toolbar
    test REG_SZ 41

    HKEY_LOCAL_MACHINEsoftwaregooglegoogle toolbar4.0

    HKEY_LOCAL_MACHINEsoftwaregooglegoogle toolbarBranding

    HKEY_LOCAL_MACHINEsoftwaregooglegoogle toolbarInstallations

    HKEY_LOCAL_MACHINEsoftwaregooglegoogle toolbarObsolete
    errorlevel was 0

    Error: The system was unable to find the specified registry key or value
    errorlevel was 1</pre>

    So do the
    REG QUERY xxx 1>nul 2>&1
    to suppress all the output, good or bad, and test the resulting errorlevel.

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  6. #6
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Remotely check if registry key exists

    I've even done it for you...
    <pre>@echo off
    :: we assume that computer names are found one per line...
    for /f %%a in (c:computers.txt) do call rocess %%a
    goto :eof

    ::--------------------------------------------------
    rocess the computername passed from the FOR command

    reg query "%1hklmsoftwaregooglegoogle toolbar" 1>nul 2>&1
    if errorlevel 1 (
    ECHO GOOGLE TOOLBAR NOT FOUND ON %1
    REM echo %1 >> usmc_nfstranspoupdatesnogoogletoolbar.txt
    ) else (
    ECHO GOOGLE TOOLBAR **FOUND** ON %1
    REM echo %1 >> usmc_nfstranspoupdatesgoogletoobar.txt
    )
    goto :eof</pre>

    After testing it "as is" on your machine, presumably in your Administrator account, remove the word REM from the two lines where found, and the entire lines starting with ECHO in capital letters. You don't always have to use PSEXEC!

    John

    PS I've not changed the TYPO in the filename "googletoobar.txt"...!!
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •