Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB Script help

Posted on 2013-05-10
3
Medium Priority
?
202 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 2000 total points
ID: 39157622
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
ID: 39158240
Awesome, this works like a charm. Thank you very much!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 39159317
No problem. Glad to help. Thanks for the grade.

Rob.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

926 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