Link to home
Start Free TrialLog in
Avatar of Simon336697
Simon336697Flag for Australia

asked on

Microsoft VBScript compilation error: Expected 'Next'

HI guys, im having an issue with this vbs file and id love your help.

Im getting the following:

d:\systems\audit.vbs(67, 11) Microsoft VBScript compilation error: Expected 'Next'

Any help greatly appreciated.
'------------------------------------------------------------------------------------------------
'Script: audit.vbs
'------------------------------------------------------------------------------------------------
 
'------------------------------------------------------------------------------------------------
'Declare Variables:
'------------------------------------------------------------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
strComputersFile = "servers.txt"
strOutputFile = "FileVersionLog.txt"
strFileToFind = "C:\Windows\System32\cpqmgmt\agentver.dll"
Set objComputers = objFSO.OpenTextFile(strComputersFile, intForReading, False)
Set objLogFile = objFSO.CreateTextFile(strOutputFile, True)
 
'------------------------------------------------------------------------------------------------
'Write a Description:
'------------------------------------------------------------------------------------------------
objLogFile.WriteLine "Script run at " & Now & VbCrLf
objLogFile.WriteLine "This file contains the version for the HP Management Agent file ""agentver.dll"", the Architecture and Model" & VbCrLf
 
'------------------------------------------------------------------------------------------------
'Read and Loop through the text file:
'------------------------------------------------------------------------------------------------
While Not objComputers.AtEndOfStream
 
	strComputer = 	objComputers.ReadLine
  	strArch = 	"Architecture Unknown"
  	strModel = 	"Model Unknown"
  	strSpack = 	"SP Unknown"
 	strVersion = 	"PSP File not found"
 
	'If you can connect to the machine, then get 1) OS, 2) SPack, 3) Architecture, 4) Model, 5) PSP Version.
 
	If Ping(strComputer) = True Then
 
  	On Error Resume Next
  		Set objWMIService = GetObject("winmgmts:" _
      		& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
  		If Err.Number = 0 Then On Error GoTo 0
 
   		'1) Get Operating System:
		'-----------------------------------------------------
		Set colOS = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
 
		For Each objOS in colOS
			strOS = objOS.Caption
		Next
 
   		'2) Get Service Pack:
		'-----------------------------------------------------
		Set colSpack = objWMIService.ExecQuery _
    		("Select * from Win32_OperatingSystem")
 
		For Each objSpack in colSpack
			strSpack = objSpack.ServicePackMajorVersion
		Next
 
   		'3) Get Architecture:
		'-----------------------------------------------------
   		Set colProcessors = objWMIService.ExecQuery _
    		("Select * From Win32_Processor")
 
   		For Each objProcessor in colProcessors
       			If objProcessor.Architecture = 0 Then strArch = "x86"
       			ElseIf objProcessor.Architecture = 1 Then strArch = "MIPS"
       			ElseIf objProcessor.Architecture = 2 Then strArch = "Alpha"
       			ElseIf objProcessor.Architecture = 3 Then strArch = "PowerPC"
       			ElseIf objProcessor.Architecture = 9 Then strArch = "x64"
       			Else strArch = "Arch Unknown"
       			End If
   		Next
 
   		'4) Get Model:
		'-----------------------------------------------------
   		Set colItems = objWMIService.ExecQuery _
    		("Select * From Win32_ComputerSystem")
 
   		For Each objItem In colItems
         		strModel = objItem.Model
      		Next
 
   		'5) Get PSP Version (Search for the PSP file, replacing the c:\ with c$):
		'-----------------------------------------------------
 		strUNCFile = "\\" & strComputer & "\" & Replace(strFileToFind, ":", "$")
 		If objFSO.FileExists(strUNCFile) = True Then strVersion = objFSO.GetFileVersion(strUNCFile) Else strVersion = "File Not there"
 
 
 objLogFile.WriteLine strComputer & vbTab & strOS & vbTab & strSpack & vbTab & strArch & vbTab & strModel & vbTab & strVersion
 
 
  	End If
 
  
Wend
 
objComputers.Close
 
MsgBox "Done"
 
Function Ping(strComputer)
 Dim objShell, boolCode
 Set objShell = CreateObject("WScript.Shell")
 boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
 If boolCode = 0 Then
  Ping = True
 Else
  Ping = False
 End If
End Function
 
 
'--------------------------------------------------------------------------------------------------------------------

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of chandru_sol
chandru_sol
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Simon336697

ASKER

Hi chandru_sol :>)

Thanks so much for your help on this.
I will give it a go and report back to you :>)
Thx chandru_sol
Hi Chandru,
Im getting the following chandru:

d:\systems\no.vbs(67, 25) Microsoft VBScript compilation error: Expected 'Next'
Still no go.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Because you use the single-line "If" statement, each line is its own "If" clause. Thus, there cannot be any "ElseIf" or "Else" or "End If" statements.
Avatar of Patrick Matthews
Badotz said:
>>Because you use the single-line "If" statement, each line is its own "If" clause. Thus, there cannot be any
>>"ElseIf" or "Else" or "End If" statements.

Small clarification, and please no points...

The single line If construction *may* contain an Else if desired:

If SomeVar = 42 Then AnotherVar = "foo" Else AnotherVar = "hee"
Thanks so much to all of you guys.
Special thanks to matthewspatrick :>)