Bonjour tout le monde,

Je viens de m'inscrire sur ce forum car je souhaite ameliorer mes connaissances VB qui sont basiques pour le moment.

Il se trouve que je suis deja confronte a une errer vbscript que pour le moment je n'arrive pas a resoudre.
En fait on m'a demande de partir du script suivant qui affiche l'icone de chaque connection reseau dans la barre d'etat.
Le script utilise la boucle For each Next et utilise la notion de collection.

Le proeble est qu'a la ligne 58 j'ai le message d'erreur " Object not a collection"

Voici le script d'origine :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'***************************************************************************************************
'******************************************** Constants ********************************************
Const HKEY_CLASSES_ROOT   = &H80000000
Const HKEY_CURRENT_USER   = &H80000001
Const HKEY_LOCAL_MACHINE  = &H80000002
Const HKEY_USERS          = &H80000003
 
'***************************************************************************************************
'******************************************* Declarations ******************************************
Set wshShell    = WScript.CreateObject("WScript.Shell")
Set wshNetwork  = CreateObject("WScript.Network")
Set fileSys     = CreateObject("Scripting.FileSystemObject")
Set objRegistry = GetObject("winmgmts:root\default:StdRegProv")
Set oProcEnv    = wshShell.Environment("PROCESS")
Set oSystem     = GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")
Set oBios       = GetObject("winmgmts:").InstancesOf("Win32_Bios")
Set objServ     = GetObject("winmgmts:").InstancesOf("Win32_Service")
Set oHardware   = GetObject("winmgmts:").InstancesOf("Win32_SystemEnclosure")
 
'***************************************************************************************************
'***************************************** Global Variables ****************************************
'**** Set Global Variables used throughout the script
Dim sModel, sManu, sHardware, sReleaseDate, sImageDate, sBIOS,sNames(),sNames1(),sNames2()
 
'**** Set Default Folders for script ***
CurrentDir     	= WshShell.CurrentDirectory & "\"
WinDir          = filesys.GetSpecialFolder(0)
WinSysDir       = filesys.GetSpecialFolder(1)
AllDesktop      = WshShell.SpecialFolders("AllUsersDesktop")
AllStartMenu    = WshShell.SpecialFolders("AllUsersStartMenu")
AllProgramMenu  = WshShell.SpecialFolders("AllUsersPrograms")
AllStartup      = WshShell.SpecialFolders("AllUsersStartup")
CurrDesktop     = WshShell.SpecialFolders("Desktop")
CurrStartMenu   = WshShell.SpecialFolders("StartMenu")
CurrPrograms    = WshShell.SpecialFolders("Programs")
CurrSendTo      = WshShell.SpecialFolders("SendTo")
CurrFavs        = WshShell.SpecialFolders("Favorites")
DefaultSendTo   = "c:\Documents and Settings\Default User\SentTo"
sProgramFiles   = oProcEnv("ProgramFiles")
If sProgramFiles = "" Then
  sProgramFiles = WshShell.RegRead _
     ("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir")
End If
 
'***************************************************************************************************
'****************************************** Script Begins ******************************************
 
'***************************************************************************************************
'**** Set all network adapters to show connection icon in system tray
Set wmiLocator    = CreateObject("WbemScripting.SWbemLocator")
strNameSpace      = "root\default"
Set wmiNameSpace  = wmiLocator.ConnectServer (strServer, strNameSpace, strUserName, strPassword)
Set objRegistry   = wmiNameSpace.Get ("StdRegProv")
lRC = objRegistry.EnumKey(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Network", sNames)
For Each name In sNames
  lRC1 = objRegistry.EnumKey(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Network\" & name, sNames1)
  If lrc1 = 0 then
    For each name1 in snames1
      lRC2 = objRegistry.EnumKey(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Network\" & name & "\" & name1, sNames2)
      If lrc2 = 0 then
        For each name2 in snames2
          If name2 = "Connection" then
            lRC3 = objRegistry.SetDWORDValue(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Network\" & name & "\" & name1 & "\" & name2, "ShowIcon", &H1)
          End if
        Next
      End if
    Next
  End if
Next
'***************************************************************************************************
 
 
'***************************************************************************************************
'**** Ensure NIC is set to Auto
hKey = "System\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, hKey, arrSubKeys
 
For each nic in GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapter")
  If(Left(nic.PNPDeviceID,7)="PCI\VEN") Then
    If (InStr(nic.Description,"Wireless")=0)Then
    	For each subkey in arrSubKeys
    		objRegistry.GetSTRINGValue HKEY_LOCAL_MACHINE,hKey&"\"&subkey,"ComponentID",sKeyValue
    		sPNPComponent = Left(nic.PNPDeviceID,37)
    		sPNPComponent =  LCase(sPNPComponent)
		If (InStr(sPNPComponent,sKeyValue)=1)Then
    		'If (sPNPComponent=sKeyValue)Then
    			If(nic.Manufacturer = "Intel") Then
      			wshshell.RegWrite "HKLM\"&hKey&"\"&subkey&"\SpeedDuplex","0","REG_SZ"
 
    			ElseIf (nic.Manufacturer = "Broadcom") Then
    				wshshell.RegWrite "HKLM\"&hKey&"\"&subkey&"\RequestedMediaType","0","REG_SZ"
    			End If
    			objRegistry.GetDWORDValue HKEY_LOCAL_MACHINE,hKey&"\"&subkey,"PnPCapabilities",sValue
    			If IsNull(sValue)Then
    			  wshshell.RegWrite "HKLM\"&hKey&"\"&subkey&"\PnPCapabilities","32","REG_DWORD"
    			Else
    				wshshell.RegWrite "HKLM\"&hKey&"\"&subkey&"\PnPCapabilities","32","REG_DWORD"
    			End If
    		End If
    	Next
    End If
  End If
Next
'**************************************************************************************************
Pour le moment je ne suis pas encore tres familier avec les boucles et les collections, c'est pour cette raison que je demande un petit coup de main

En tout cas merci par avance du temps que vous passerez sur mon cas

Bonne journee

Franck