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.
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