[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Microsoft VBScript compilation error: Expected 'Next'

Posted on 2009-04-19
9
Medium Priority
?
2,500 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:Simon336697
9 Comments
 
LVL 12

Accepted Solution

by:
chandru_sol earned 1520 total points
ID: 24181940
Try this version....
'------------------------------------------------------------------------------------------------
'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
			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

0
 
LVL 1

Author Comment

by:Simon336697
ID: 24182016
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
0
 
LVL 1

Author Comment

by:Simon336697
ID: 24182024
Hi Chandru,
Im getting the following chandru:

d:\systems\no.vbs(67, 25) Microsoft VBScript compilation error: Expected 'Next'
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Simon336697
ID: 24182575
Still no go.
0
 
LVL 29

Assisted Solution

by:Badotz
Badotz earned 480 total points
ID: 24182839
I believe the If..End If block at lines 65 through 73 should be:


                For Each objProcessor in colProcessors
                        strArch = "Arch Unknown"
                        If objProcessor.Architecture = 0 Then strArch = "x86"
                        If objProcessor.Architecture = 1 Then strArch = "MIPS"
                        If objProcessor.Architecture = 2 Then strArch = "Alpha"
                        If objProcessor.Architecture = 3 Then strArch = "PowerPC"
                        If objProcessor.Architecture = 9 Then strArch = "x64"
                Next

Open in new window

0
 
LVL 29

Expert Comment

by:Badotz
ID: 24182843
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.
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 24184416
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"
0
 
LVL 1

Author Comment

by:Simon336697
ID: 24190042
Thanks so much to all of you guys.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 24190046
Special thanks to matthewspatrick :>)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month18 days, 3 hours left to enroll

830 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