Solved

VB Script help

Posted on 2013-05-10
3
181 Views
Last Modified: 2013-05-12
Obvious amateur with scripting and I need some help.

Here is the bit
On Error Resume Next

Dim FSO
Dim objStream

Const TriStateFalse = 0
Const FILE_NAME = "Report.csv"

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objStream = FSO.CreateTextFile(FILE_NAME, _
	True, TristateFalse)



strSubnetPrefix = "172.0.0."
intBeginSubnet = 60
intEndSubnet = 120

For i = intBeginSubnet To intEndSubnet
	strComputer = strSubnetPrefix & i
		if strcomputer = "" then
			wscript.quit
		else
		Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
			("select * from Win32_PingStatus where address = '" & strcomputer & "'")
		For Each objStatus in objPing
			If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then 
			else
				set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & _
			strComputer & "\root\cimv2")
				Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
				Set objItems = objWMIService.ExecQuery("Select * from Win32_BIOS")
				For Each objComputer in colSettings 
				set objwmiservice = nothing
				set colsettings = nothing
				set objping = nothing
						objStream.WriteLine objComputer.name & "," & objcomputer.username & "," & strcomputer & "," & objcomputer.model
					For Each objItem in objItems
						objSteam.WriteLine objItem.serialnumber
					next						
					
				next
			end if	
		next
        end if
Next

Open in new window


What I am trying to do is query both Win32_ComputerSystem and Win32_BIOS and have it write to the same file... and I don't know what I am doing ;)
0
Comment
Question by:hQWeedEater
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
Comment Utility
Hi, untested, but try this.  I think the main problem is that you were looping through the BIOS *while* looping through the COMPUTERSYSTEM, which means you'll loop it too much.

I've used only .Write for the first output, then .WriteLine for the rest.

Regards,

Rob.

'On Error Resume Next

Dim FSO
Dim objStream

Const TriStateFalse = 0
Const FILE_NAME = "Report.csv"

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objStream = FSO.CreateTextFile(FILE_NAME, True, TristateFalse)


strSubnetPrefix = "172.0.0."
intBeginSubnet = 60
intEndSubnet = 120

For i = intBeginSubnet To intEndSubnet
	strComputer = strSubnetPrefix & i
	If strcomputer = "" then
		WScript.quit
	Else
		Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
			("select * from Win32_PingStatus where address = '" & strcomputer & "'")
		For Each objStatus in objPing
			If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then 
			Else
				Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
				Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
				Set objItems = objWMIService.ExecQuery("Select * from Win32_BIOS")
				For Each objItem in objItems
					objSteam.Write objItem.serialnumber & ","
				Next						
				For Each objComputer in colSettings
					objStream.WriteLine objComputer.name & "," & objcomputer.username & "," & strcomputer & "," & objcomputer.model
				Next
				Set objwmiservice = nothing
				Set colsettings = nothing
				Set objping = nothing
			End if	
		Next
		End if
Next

Open in new window

0
 
LVL 1

Author Closing Comment

by:hQWeedEater
Comment Utility
Awesome, this works like a charm. Thank you very much!
0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
No problem. Glad to help. Thanks for the grade.

Rob.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now