Clean Batch File - Deploying Service Pack 1 for Win7x64Pro

Posted on 2011-04-28
Last Modified: 2012-05-11
I've got a basic computer startup script to deploy Windows 7 SP1:

\\svr\share$\win7sp1\windows6.1-kb976932-x64.exe /quiet /nodialog /forcerestart

I want to add something ahead of this line to have the script check whether SP1 is already installed, and if it is, to terminate the script entirely.  Can this still be done w/ batch or does it have to be done with VBS?  What's the syntax?
Question by:NAMEWITHELD12
    LVL 70

    Expert Comment

    by:Chris Dent
    I can't speak for batch scripting really, but WMI knows. And you can get CMD to tell you it with:

    WMIC OS GET CSDVersion

    If the output from that can be tested...

    LVL 7

    Accepted Solution

    There's a few ways it can be done, mostly all dealing with server pack or build numbers.

    Here's my stab at it using a one-line script, but it's a pretty hefty one-liner.  I went with a REG QUERY comparing the "CurrentBuildNumber" value since Microsoft actually started incrementing that when service packs are added since Microsoft Vista.  Windows 7 is "7600" and Windows 7 SP1 is "7601".

    For /f "tokens=3 delims= " %%A In ('REG QUERY "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /V CurrentBuildNumber ^|Find "CurrentBuildNumber"') Do (If %%A LSS 7601 \\svr\share$\win7sp1\windows6.1-kb976932-x64.exe /quiet /nodialog /forcerestart)

    Open in new window

    Let me know if you need something additional such as OS type detection (WinVista, Win7, etc) as well
    LVL 1

    Author Comment

    I'll give this a shot on my dev box and post results
    LVL 1

    Author Closing Comment

    Short and sweet, it seems to work like a charm..thanks!

    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).

    Join & Write a Comment

    I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
    Ever wondered why Windows 8 and 10 don't seem to accept your GPO-based software deployment while Windows 7 does? Read on.
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    746 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

    19 Experts available now in Live!

    Get 1:1 Help Now