Solved

Simple: detect OS and SP

Posted on 2004-09-11
7
4,036 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 96

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 96

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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