• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

changing network card speed registry setting using vb script

I need to change the link speek of some broadcom and intel cards on remote computers. I am receiving the error "object not in collection" when  testing the vb script below. Line 16 is the start of the array "For Each Subkey In arrSubKeys". Any help would be appreciated. Thanks.

Line: 16
Char: 1
Error:Object not a collection
Code: 800A01C3



Const HKLM = &H80000002

strComputer = "."
Set fso = CreateObject("Scripting.FileSystemObject")
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
sNetPath = " System\Currentcontrolset\Control\Class\{4D36E972-E325-11CE-BFC1-08002be10318}"

SetSpeedDuplex()

Sub SetSpeedDuplex()
Dim section, strValue, subkey, arrSubKeys

objRegistry.EnumKey HKLM, sNetPath, arrSubKeys

For Each Subkey In arrSubKeys

objRegistry.GetStringvalue HKLM, sNetPath & "\" & subkey, "ComponentId", strValue
if not isnull(strValue) then
strValue = lcase(strValue)
section = left(replace(replace(strValue, "pci\ven_", ""), "&dev_",""), 8)
ReadDuplexIni section, subkey
end if
Next
End Sub

Sub ReadDuplexIni(section, subkey)
Dim ini, line, file

file = "spddplx.ini"
If fso.FileExists(file) Then
Set ini = fso.OpenTextFile(file, 1, False)
Do While ini.AtEndOfStream = False
line = ini.ReadLine
If lcase(line) = "[" & lcase(section) & "]" Then
line = ini.ReadLine
Do While Left(line, 1) <> "["
If left(line, 1) <> ";" and len(line) > 0 Then
UpdateReg line, subkey
End If
If ini.AtEndOfStream Then Exit Do
line = ini.ReadLine
Loop
Exit Do
End If
Loop
ini.Close
End If
End Sub

Sub UpdateReg(line, subkey)
Dim lRC

key = split(line, "=")
lRC=objRegistry.SetStringValue(HKLM, sNetPath & "\" & subkey, key(0),key(1))
End Sub
0
cdmann
Asked:
cdmann
  • 2
  • 2
  • 2
1 Solution
 
Lester_ClaytonCommented:
Line 16 refers to

For Each Subkey In arrSubKeys

Open in new window


It just means that arrSubKeys is not an array.

Try Dimention it as an array.  Example:

Dim section, strValue, subkey, arrSubKeys()

Open in new window


Can I also please make a suggestion that if you paste code, you use the code tag, or the Code block :)  It makes it much easier to read.

Many Thanks!
0
 
cdmannAuthor Commented:
I get the same error when I do that. Thanks for taking the time.

Dim section, strValue, subkey, arrSubKeys()
0
 
Lester_ClaytonCommented:
It should definately be an array.  Can you add a line in to try to print arrSubKeys() to screen so you can validate that there is a result for it to work with?  If there is no result, it can naturally cause an error too.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
RobSampsonCommented:
Does it help if you remove the space from the start of this line, before System:
sNetPath = " System\Currentcontrolset\Control\Class\{4D36E972-E325-11CE-BFC1-08002be10318}"

Open in new window


Rob.
0
 
cdmannAuthor Commented:
The space (removed) between the quotation mark and system was causing the issue. Also, for info purposes in regards to the  spddplx.ini file (add an asterisk next to *speedDuplex for intel cards as this is how it appears in the windows registry). Thanks for your help.

sNetPath = "System\Currentcontrolset\Control\Class\{4D36E972-E325-11CE-BFC1-08002be10318}"
0
 
RobSampsonCommented:
Great. 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.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now