Solved

Simple: detect OS and SP

Posted on 2004-09-11
7
3,981 Views
Last Modified: 2010-05-18
Hi,


I need a batch file to detect what is the OS and Service Pack the pc has on and save the OS in the variable %os and the SP in the variable %sp


Thanks
0
Comment
Question by:zawa
  • 2
7 Comments
 
LVL 41

Accepted Solution

by:
graye earned 25 total points
ID: 12038666
Here is a VBScript that will do what you want... it requires the SETX.EXE command (from either the Resource Kit or Support Tools).  You might have to place the SETX.EXE on a network share, since you probably won't be certain if it exists on every client PC.

dim obj, objs, wsh
dim OperatingSystem, ServicePack

Set objs = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
for each obj in objs
    OperatingSystem = obj.Caption
    ServicePack = obj.CSDVersion
next

Set wsh = CreateObject("WScript.Shell")
wsh.run "setx OS " & chr(34) & OperatingSystem & chr(34) & " /m", 7, false
wsh.run "setx SP " & chr(34) & ServicePack & chr(34) & " /m", 7, false
0
 
LVL 95

Assisted Solution

by:Lee W, MVP
Lee W, MVP earned 25 total points
ID: 12038724
The following command relies only on DOS CMD extensions and the utility PSINFO, available free in the PSTOOLS package from SysInternals:
http://www.sysinternals.com/ntw2k/freeware/pstools.shtml

---------------8<------------------
@Echo off
FOR /f "usebackq tokens=2 delims=:" %%a in (`psinfo ^| find /i "Product version"`) do SET ProdVer=%%a
FOR /f "usebackq tokens=2 delims=:" %%a in (`psinfo ^| find /i "Service pack"`) do SET Prodsp=%%a
Echo Windows %Prodver%, Service Pack %prodsp%
---------------8<------------------

The above script sets Prodver and prodsp environment variables to the version of Windows and the service pack respectively.
0
 
LVL 1

Assisted Solution

by:shanekelly_7
shanekelly_7 earned 25 total points
ID: 12240229
One problem the Variable %os% cannot be Overwritten as it is a fixed variable. therefor i will have to use %os1%
This is how you do it:~

----Start of Batch Script!----
@echo off
systeminfo | find /n "OS" > temp.txt
for /f "tokens=2* delims=:" %%a in ('type temp.txt ^| find "[4]"') do set sp=%%a
for /f "tokens=2* delims=:" %%a in ('type temp.txt ^| find "[3]"') do set os1=%%a
del temp.txt
set os1=%os1:  =%
set sp=%sp:  =%
:: The variables %sp% and %os% are Now set.
-----End of Batch Script!----

Good Luck!
- Shane
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12436065
I feel all three comments answer the question, though ShaneKelly has a valid point about the %OS% variable and graye's comment did attempt to reset that.  

I believe my solution represents the best answer where the OS is NT, 2000, or XP.  I do not believe systeminfo functions in NT.  And the VBScript solution is both longer and requires the computer have VSH installed and running (NT 4 might be an issue with this).  

Regardless, I think the points should be split evenly amongst the three of us.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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