Solved

Simple: detect OS and SP

Posted on 2004-09-11
7
3,991 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

825 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