Solved

Simple: detect OS and SP

Posted on 2004-09-11
7
3,970 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

10 Experts available now in Live!

Get 1:1 Help Now