IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Error dans un script VB permettant d'afficher l'icone reseau pour chaque connection reseau


Sujet :

VBScript

  1. #1
    Candidat au Club
    Inscrit en
    Juillet 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 4
    Points : 2
    Points
    2
    Par défaut Error dans un script VB permettant d'afficher l'icone reseau pour chaque connection reseau
    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

  2. #2
    Modérateur
    Avatar de l_autodidacte
    Homme Profil pro
    Retraité : Directeur de lycée/Professeur de sciences physiques
    Inscrit en
    Juillet 2009
    Messages
    2 416
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Retraité : Directeur de lycée/Professeur de sciences physiques
    Secteur : Enseignement

    Informations forums :
    Inscription : Juillet 2009
    Messages : 2 416
    Points : 5 808
    Points
    5 808
    Par défaut
    Le problème se situe à ce niveau :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set objRegistry = GetObject("winmgmts:root\default:StdRegProv")
    Il faut remplacer par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set objRegistry = GetObject("winmgmts:\\root\default:StdRegProv")
    pour pouvoir accéder au réseau.

  3. #3
    Candidat au Club
    Inscrit en
    Juillet 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Merci de ta reponse rapide mais je continue d'avoir la meme erreur a savoir

    "object not a collection"

    Je continue de chercher du cote de ma boucle

  4. #4
    Modérateur
    Avatar de l_autodidacte
    Homme Profil pro
    Retraité : Directeur de lycée/Professeur de sciences physiques
    Inscrit en
    Juillet 2009
    Messages
    2 416
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Retraité : Directeur de lycée/Professeur de sciences physiques
    Secteur : Enseignement

    Informations forums :
    Inscription : Juillet 2009
    Messages : 2 416
    Points : 5 808
    Points
    5 808
    Par défaut
    En modifiant le code tel que je l'ai mentionné, je reçois le message d'erreur suivant :
    Ligne : 13
    caractère : 1
    Erreur: Le serveur distant n'existe pas ou n'est pas disponible: 'GetObject'

    et là, il n'est plus question d'objet qui n'est pas une collection.
    Il faut peut-être voir de ce côté-là.

  5. #5
    Candidat au Club
    Inscrit en
    Juillet 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Oui c'est vrai j'ai la meme erreur

    En meme temps je ne comprends pas trop dans la mesure ou j'execute le script localement sur un poste XP SP3.

    Mais tu as raison je vais aussi regarder dans cette direction

    Merci en tout cas

  6. #6
    Candidat au Club
    Inscrit en
    Juillet 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Finalement j'ai decide de modifir mon script en m'appuyant sur WMI :

    Pour info voici le code :


    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
    '***************************************************************************************************
    '******************************************** 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
    '***************************************************************************************************
    Dim objReg
    Dim objWMIService
    Dim colNetCards
    Dim objNetCard
    Dim strNICguid
    Const HKLM = &H80000002
    strComputer = "." 
    strKeyName = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\"
    strKeyName001 = "SYSTEM\CurrentControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\"
    dwValue = 1
     
    Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer& "\root\default:StdRegProv")
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer& "\root\cimv2")
    Set colNetCards = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
      For Each objNetCard in colNetCards
        strNICguid = objNetCard.SettingID
        objReg.SetDWORDValue HKLM, strKeyName & strNICguid & "\Connection", "ShowIcon", dwValue
        objReg.SetDWORDValue HKLM, strKeyName001 & strNICguid & "\Connection", "ShowIcon", dwValue
      Next
    Set objReg = Nothing
    Set objWMIService = Nothing
    Du coup je ferme mon poste

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 12
    Dernier message: 02/02/2013, 00h14
  2. afficher ses attributs (caractéristiques) pour chaque article
    Par loic20h28 dans le forum Langage SQL
    Réponses: 5
    Dernier message: 04/02/2009, 16h41
  3. Réponses: 2
    Dernier message: 26/03/2007, 16h47
  4. [Mail] Parse error dans mon script de mailer
    Par Le Parrain dans le forum Langage
    Réponses: 6
    Dernier message: 30/06/2006, 15h08
  5. script cgi permettant d'afficher l'heure..
    Par Nemesys dans le forum C
    Réponses: 12
    Dernier message: 27/04/2006, 13h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo