Need help with getting Win Versions and use it as argument

Posted by Dpcompower on Tue 09 Aug 2011 01:28 AM — 3 posts, 23,385 views.

#0
Please help me sort this out!!!
We started a vbs a below. What we need is read computer names from text file, then copy file to each PC depending on the Windows version of that PC. Somehow (it guess I'm not good enough) the part where processing Windows version didn't work correctly. If I remove and just copy file without check Win versions then it works fine.


'==============================

Option Explicit
'==============================
'Read name from TTT.txt file and copy file depending on Windows Version
'==============================
'******************************
Sub CopyFileToPCs(FileName)
  Const dFileName  = "ProxyFix.bat"
  Const TargetDir = "\c$\Documents and Settings\All Users\Start Menu\Programs\Startup\"
  Const TargetDir1 = "\c$\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\"
  Const ForReading = 1
  Const Overwrite = TRUE
  Dim objFSO
  Dim objFile
  Dim strComputer
  Dim strVersion
  Dim strVers

  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile(FileName)
  On Error Resume Next
  Do Until objFile.AtEndOfStream
    strComputer = objFile.ReadLine
	'WScript.ECho(strComputer)
	strVers = GetVer(strComputer)
	WScrtipt.ECho(strVers)
	If strVers = "Microsoft Windows X" Then
    objFSO.CopyFile dFileName, "\" & strComputer & TargetDir & dFileName, Overwrite
	Else
	objFSO.CopyFile dFileName, "\" & strComputer & TargetDir1 & dFileName, Overwrite
	End If
  Loop
End Sub

Function GetVer(ComputerName)
Dim strVersion
Dim strVer
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & ComputerName & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
	strVersion = objOperatingSystem.Caption
	strVer = Left(strVersion, 19)
	Wscript.Echo strVer
	GetVer = strVer
    'Wscript.Echo objOperatingSystem.Caption & "  " & objOperatingSystem.Version
Next
End Function

CopyFileToPCs("TTT.txt") 'testing
USA Global Moderator #1
First, there's no such thing as "Windows X".

Second, from http://mushclient.com/scripts/doc.php?function=GetInfo
Quote:
You can deduce the operating system as follows by using GetInfo (265) through to GetInfo (268):

If platform ID == 0 (Win32s) then:
you should not get this, MUSHclient doesn't run under Win32s

If platform ID == 1 (Windows 95-style versions) then:

If major == 4 and minor == 0 then: Windows 95
If major == 4 and minor == 10 then: Windows 98 (or 98SE)
If major == 4 and minor == 90 then: Windows ME

If platform ID == 2 (Windows NT versions) then:

If major == 3 then: Windows NT 3.51
If major == 4 then: Windows NT 4
If major == 5 and minor == 0 then: Windows 2000
If major == 5 and minor == 1 then: Windows XP
If major == 5 and minor == 2 then: Windows Server 2003
If major == 6 and minor == 0 then: Windows Vista, or Windows Server Longhorn
If major == 6 and minor == 1 then: Windows 7

Amended on Tue 09 Aug 2011 02:25 PM by Fiendish
Netherlands #2
And third - this is a forum dedicated to VBScripting inside the MUSHclient application, something you very likely aren't looking to do. :)

I am sure people are willing to help you with your questions, but it is unlikely that we will be able to help you as well as, say, a forum dedicated to general-purpose VBS scripting.