reg key XP get ostype

Posted on 2011-05-06
Last Modified: 2012-05-11
We have a login script, batch file. We need a portion of it executed only if the ostype is XP. Was thinking about something like reading the registry key product name with reg query.

IF something GOTO next ELSE GOTO exit

How can i do this?
Question by:eltel-it-nor

    Expert Comment

    with command 'ver'  you see the version of windows

    Author Comment

    Ok, thanks. How can i use this in a batch script?
    LVL 4

    Expert Comment

    @echo OFF

    set KEY_NAME="HKEY_CURRENT_USER\Software\Microsoft\Command Processor"
    set VALUE_NAME=DefaultColor

    FOR /F "usebackq skip=4 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
        set ValueName=%%A
        set ValueType=%%B
        set ValueValue=%%C

    if defined ValueName (
        @echo Value Name = %ValueName%
        @echo Value Type = %ValueType%
        @echo Value Value = %ValueValue%
    ) else (
        @echo %KEY_NAME%\%VALUE_NAME% not found.

    Kindly refer;
    LVL 8

    Expert Comment

    You can try the following code.

    set Version=
    for /f "skip=1" %%v in ('wmic os get version') do if not defined Version set Version=%%v
    for /f "delims=. tokens=1-3" %%a in ("%Version%") do (
      set Version.Major=%%a
      set Version.Minor=%%b
      set Version.Build=%%c
    set GTR_XP=
    if %Version.Major%==5 if %Version.Minor% GTR 1 set GTR_XP=1
    if %Version.Major% GTR 5 set GTR_XP=1
    if defined GTR_XP (

    Open in new window

    LVL 5

    Expert Comment

    reg query "hklm\software\microsoft\windows nt\currentversion" /v productname | findstr /c:"Windows XP"
    if errorlevel 1 echo Not XP and goto :EOF
    echo XP!!
    LVL 5

    Accepted Solution

    Should be:

    reg query "hklm\software\microsoft\windows nt\currentversion" /v productname | findstr /c:"Windows XP"
    if errorlevel 1 echo Not XP && goto :EOF
    echo XP!!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    twoTwo  challenge 35 72
    No More local names in the certificate starting November 2015 4 70
    changeXy challenge 13 40
    array11 challenge 16 40
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now