none
Reading the registry from a .bat file RRS feed

  • Question

  • I've searched a bit on web before asking and I apologies a head of time but my knowledge of .bat files is a little lacking. Currently I have a working .bat file I created, but was looking to adding something extra to it and just can't seem to find exactly what I need.. What i'm looking to do is at the top of .bat file I want it to read the registry here HKEY_LOCAL_MACHINE\SOFTWARE\IS_DEPT\Simage\HW\Platform

    Under Platform we either have 2 types LT or DT. (laptop or desktop)

    What I want to do is at the top of my bat file have it search this key. If it has the value LT I want it to continue on with the script. If the value is DT I want it to not run the rest of the script and go to :end

    If this is possible can someone provide me with the commands to put at the top of the script with also the IF commands to continue or go to :end

    Wednesday, February 26, 2014 11:46 PM

Answers

  • NVM got it. Found a coworker that has some skills.

    @echo off &setlocal
    for /f "tokens=2*" %%a in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\IS_DEPT\Simage\HW /v Platform') do set "var=%%b"
    if "%var%"=="LT" GOTO HOME
    if "%var%"=="DT" GOTO NOOOOPE

    Thursday, February 27, 2014 5:01 PM

All replies

  • wmic systemenclosure get chassistypes |findstr '{*}'

    Chassis type are here: http://msdn.microsoft.com/en-us/library/aa394474(v=vs.85).aspx

    Or use REG:
    reg query HKEY_LOCAL_MACHINE\SOFTWARE\IS_DEPT\Simage\HW\Platform


    ¯\_(ツ)_/¯

    • Proposed as answer by Peter Ziganki Thursday, February 27, 2014 8:04 AM
    Thursday, February 27, 2014 12:37 AM
  • Thanks for you reply but I'm still a little lost with the reply.

    What is the rest of the commands?

    I understand this will query the registry, but what about searching for "LT or DT" and the IF/GOTO Commands?

    reg query HKEY_LOCAL_MACHINE\SOFTWARE\IS_DEPT\Simage\HW\Platform

    I think my confusion is how to define LT or DT as the variable. I keep finding %errorlevel%  variable, but that seems to only define on (1) or off (0)

    Here's what I have so far and I dont' think it's correct.

    reg query HKEY_LOCAL_MACHINE\SOFTWARE\IS_DEPT\Simage\HW\Platform /f
    if "%ERRORLEVEL%" == "LT" GOTO HOME
    if "%ERRORLEVEL%" == "DT" GOTO NOOOOPE

    Thursday, February 27, 2014 3:33 PM
  • reg query .... | findstr /C:"DT"

    ERRORLEVEL wil be 0 if successful.


    ¯\_(ツ)_/¯

    Thursday, February 27, 2014 3:53 PM
  • NVM got it. Found a coworker that has some skills.

    @echo off &setlocal
    for /f "tokens=2*" %%a in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\IS_DEPT\Simage\HW /v Platform') do set "var=%%b"
    if "%var%"=="LT" GOTO HOME
    if "%var%"=="DT" GOTO NOOOOPE

    Thursday, February 27, 2014 5:01 PM