Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting OS version via script. 1

Status
Not open for further replies.

GVN

MIS
Dec 2, 2005
238
US
I'm trying to write a script that will detect the OS vesion, either Win XP Pro or Win 2000 Pro, so that I can tell the PC which patch to run silently.Does anyone know the syntax that I need to use to pull the version info and then have it check against it?

GVN
 
type ver on command line.

-=True wisdom comes from knowing you know nothing.=-
 
you can type ver on command line but direct it to a text file:
then parse the file and get your version. you can put these inside a script file
like this:

Set wshshell = WScript.CreateObject("WScript.Shell")
wshshell.Run("cmd.exe /c ver > c:\myver.txt")


now the version information will be in myver.txt
parse the myver.txt file and

use this command in the same vbs
msgbox("the version is: " & left(vertext,1,50))


 
The best and most reliable means is to use WMI.

here is a script you can use. Save to a VBS file and double click. It will ask for a machine name to check. Obviously I wrote this for network use. For the local machine you can just type a single period.

Code:
On Error Resume Next
strComputer = InputBox("Enter PC Name or IP Address","GetOS")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
   Report = Report & objItem.CSName & " running " & objItem.Caption & " is at " & objItem.CSDVersion & vbCrLf
Next

WScript.Echo Report

I hope you find this post helpful.

Regards,

Mark
 
THANKS for the help!!! These VBS scripts are great, but is it not possible to do it from DOS as well? I didn't want to have to have any user interaction, if possible. It's for logon scripts...

GVN
 
Well, you are talking to the login script King. What is it that you want to do with it? Your login scripts should be vbscript at this point. If not please take a look at my FAQ on the subject. faq329-5798

You can modify the script to not prompt and hard code it to:
strComputer = "."

When executed in a login script it will always run on the local computer.

You can then assign 1 or 2 variables that show OS major ver and another fo SP level like this:

For Each objItem in colItems
OSVer = objItem.Caption
SPVer = objItem.CSDVersion
Next


I hope you find this post helpful.

Regards,

Mark
 
The request was for OS version not DOS version. As this is the XP Pro forum I'm confident in the assumtion that the need is to identify that a PC is in fact runnign XP and maybe identify which SP level. Are you perhaps taking my last post out of context and thinking that that code is standalone?

Do you actually know sombody still running DOS?

I hope you find this post helpful.

Regards,

Mark
 
no, not at all. that wasn't the point of my comment. i was responding also to rodrunner's comment of running ver on command line.
 
I was wanting to be able to do something similiar to this, although I know that this syntax will NOT work, it's just written to communicate my concept that I am wanting:

IF OS EQUALS "Microsoft Windows 2000 [Version 5.00.2195]" CALL "\\SERVER1\NETLOGON\Windows2000-KB912919-x86-ENU.EXE /passive"

IF OS EQUALS "Microsoft Windows XP [Version 5.1.2600]" CALL "\\SERVER1\NETLOGON\WindowsXP-KB912919-x86-ENU.exe /passive"

From what I've seen, vbs scripts can't do this, but I really don't know vbs scripting hardly at all... What would you recommend?

GVN
 
Don't underestimate the power of VBScript. It can do WAY more than batch files.

Code:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set WSHShell = CreateObject("Wscript.Shell")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

For Each objItem in colItems
   OSVer = objItem.Caption
Next

If InStr(1,OSVer,"XP") Then
	WSHShell.Run("\\SERVER1\NETLOGON\WindowsXP-KB912919-x86-ENU.exe /passive")
Elseif InStr(1,OSVer,"2000") 
	WSHShell.Run("\\SERVER1\NETLOGON\Windows2000-KB912919-x86-ENU.EXE /passive")
Else
	WScript.Quit
End If

I hope you find this post helpful.

Regards,

Mark
 
AWESOME, thanks!

Can you recommend a good book on learning VBS?

GVN
 
Yea, I'd go with microsoft.com/scripting. Download the vbscript manual and look that over. I'd also download the script repository and scriptomatic as each will get you started with many usable samples to start your own scripts from.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top