Solved

Batch with reg Query for XP SP1 installed

Posted on 2004-10-30
1,019 Views
Last Modified: 2008-01-09
I am trying to create batch file with Reg Query that will tell me if XP Service Pack 1 is installed
can some one assist me please

Thanks!!
Echo off
cls
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\BuildLab\2600.xpsp2.030422-1633"
if errorlevel 1 goto UnohaveSP1
if errorlevel 0 goto UhaveSP1
:UnohaveSP1
echo :-(
goto end
:UhaveSP1
echo :-D hurray!!!!!!!!!!!!!!!!
goto end
:end
pause
0
Question by:lf_lake
    13 Comments
     
    LVL 34

    Expert Comment

    by:sramesh2k
    Hi,

    See if the WMI script helps:

    Identifying the Latest Installed Service Pack:
    http://www.microsoft.com/resources/documentation/windows/2000/server/scriptguide/en-us/sas_cpm_tscm.mspx
    0
     
    LVL 9

    Expert Comment

    by:DrWarezz
    You're just about there, try this:


    :----8<------------------------------ FileName.bat --------------------------------------:
    @ECHO OFF
    CLS
    reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\BuildLab\2600.xpsp2.030422-1633"
    set err=%errorlevel%

    if %err%==0 goto :UHAVESP1
    if %err%==1 goto :UNOHAVESP1

    :DEFAULT
    echo An error occured. The returned errorlevel is: %err% & goto :EOF

    :UNOHAVESP1
    echo You do not have SP1 installed. & goto :EOF

    :UHAVESP1
    echo You have SP1 installed. & goto :EOF

    :EOF
    echo.
    echo [Press any key to exit ...]
    pause >>NUL
    exit
    :----8<------------------------------ FileName.bat --------------------------------------:

    Good luck!
    [r.D]
    0
     
    LVL 6

    Expert Comment

    by:kapes
    if u can run vbscript then, u won't to rely on reg.exe to be present on all machines...

    try this


    ---------------- CheckSP1.vbs ------------------------------------
    Dim RegPath, oWshShell, RegValue

    RegPath = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\BuildLab\2600.xpsp2.030422-1633"

    On Error Resume Next
    Set oWshShell = CreateObject ("WScript.Shell")

    RegValue = oWshShell.RegRead (RegPath)

    If Err Then
    'oWshShell.Popup "Error Accessing registry key (" & Err.Number & ") : " & Err.Description,0,"Check XP SP 1",vbCritical
    oWshShell.Popup ":-( , XP SP1 is NOT installed",0,"Check XP SP 1",vbCritical
    Err.Clear
    Else
    oWshShell.Popup "Registry path exists, so XP SP 1 is installed !!",0,"Check XP SP 1",vbInformation
    End If

    ----------------------------------------------------------------




    0
     

    Author Comment

    by:lf_lake
    Unfortunately, neither of thes work ... the batch file runs straight the and shows no messages ... the vb script show XP SP1 as not being installed

    0
     
    LVL 9

    Expert Comment

    by:DrWarezz
    Very strange -- have you tried sramesh2k's idea?

    [r.D]
    0
     
    LVL 6

    Expert Comment

    by:kapes
    r u sure... u r checking the right key for existence of SP1 ?

    0
     

    Author Comment

    by:lf_lake
    This is the key in my registry where the "2600.xpsp2.030422-1633" appears
    HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
    there is a string word value called "BuildLab" which has the data value of  "2600.xpsp2.030422-1633"

    my apologies if this is not correct, however this is the value I am seeing.  If this is not the correct key to query kindly advise

    Kind Regards
    0
     
    LVL 9

    Accepted Solution

    by:
    Going by the data: 2600.xpsp2.030422-1633, that's actually created if SP2 is installed, and NOT SP1..

    Also, you say that: "there is a string word value called "BuildLab" which has the data value of  "2600.xpsp2.030422-1633""
    Well, in that case, the REG QUERY method that we've been trying won't work..

    You must use another method to check the value of the key, and compare it...

    I haven't tested this but it should work:

    :-----8<------------------------------------- FileName.bat --------------------------------------------:
    @echo off

    TITLE SP2 Installation Verifier
    COLOR 70

    CLS
    ECHO.
    ECHO Reading registry ...

    PING -N 1 LOCALHOST >>NUL

    REG QUERY HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion /v BuildLab > temp.txt

    find /i "2600.xpsp2.030422-1633" temp.txt >>NUL
    set err=%errorlevel%

    del temp.txt

    if %err% NEQ 0 (
       ECHO.
       ECHO It would appear that SP2 is NOT installed.
       ECHO.
       ECHO [press any key to exit]
       PAUSE >>NUL
       EXIT
    )

    ECHO.
    ECHO It would appear the SP2 IS installed.
    ECHO.
    ECHO [press any key to exit]
    PAUSE >>NUL
    EXIT
    :-----8<------------------------------------- FileName.bat --------------------------------------------:

    gL,
    [r.D]
    0
     
    LVL 6

    Expert Comment

    by:kapes
    ohh... then buildlab is not the key ...

    for XP SP2 I check for the existence of KEY,

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP2\KB11113

    for XPSP1 I don't know, it might resamble something like this

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP1

    Go to this key ... and see.. what is the KBnumber under which it says "Windows XP Service Pack 1"
    append that number at the end...as it is done for SP2 then change that in the script..

    you have to change the script as following...


    ---------------- CheckSP1.vbs ------------------------------------
    Dim RegPath, oWshShell, RegValue

    RegPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP1"

    On Error Resume Next
    Set oWshShell = CreateObject ("WScript.Shell")

    RegValue = oWshShell.RegRead (RegPath)

    If Err Then
    'oWshShell.Popup "Error Accessing registry key (" & Err.Number & ") : " & Err.Description,0,"Check XP SP 1",vbCritical
    oWshShell.Popup ":-( , XP SP1 is NOT installed",0,"Check XP SP 1",vbCritical
    Err.Clear
    Else
    oWshShell.Popup "Registry path exists, so XP SP 1 is installed !!",0,"Check XP SP 1",vbInformation
    End If

    ----------------------------------------------------------------

    OR

    if u going individually on each machine for checking it... then

    run the follwing command at command prompt it will give you nice HTML table listing of all the patches installed on current machine...

    wmic /output:%temp%\patches.htm qfe get /format:htable && start %temp%\patches.htm
    0
     

    Author Comment

    by:lf_lake
    Many thanks to all who have helped so far.  '2600.xpsp2.030422-1633' is still showing as Service Pack 1 I am being led to believe that it differs whether you have a dell CD or a Corporate CD the build number is different
    Thanks again


    Many thanks to  DrWarezz for your solution
    0
     
    LVL 9

    Expert Comment

    by:DrWarezz
    ;-)
    0
     
    LVL 6

    Expert Comment

    by:kapes
    did u try this command...

    wmic /output:%temp%\patches.htm qfe get /format:htable && start %temp%\patches.htm
    0
     
    LVL 6

    Expert Comment

    by:kapes
    :-).... r u using the right key to check the SP2 is installed or not....

    Did u read my comments...
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    Ok I have been working on this for some time having learned and gained certification in XenDesktop 4 along came version 5 which was released last month. Since then I have been working to deploy XenDesktop 5 in a small environment with only 2 virt…
    If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    877 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

    11 Experts available now in Live!

    Get 1:1 Help Now