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

VB.NET Discussion :

problème d'exeption avec un objet


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Décembre 2006
    Messages
    158
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 158
    Par défaut problème d'exeption avec un objet
    Bonjour à tous,
    voilà j'ai un petit souci, je réalise une petite application de test qui me permet de me connecter à l'active directory. Une fois connecté à l'AD, l'application va tenter de se connecter à toutes les machines pour récupérer la date et l'heure du dernier reboot, en utilisant la classe win32_OperatingSystem, et m'afficher pour chaque machine sa date et heure de dernier reboot, sinon il affiche une message d'erreur pour les machines auquelles il n'a pas pu se connecter.

    Lorsque j'execute le programme j'obtient le message d'erreur suivant :
    Compiler Error Message: BC30367: Class 'System.DirectoryServices.SearchResult' cannot be indexed because it has no default property.

    Source Error:



    Line 50:
    Line 51: 'For Each currentResult As ManagementObject In theCollectionOfResults
    Line 52: response.write("Drive:"& result("LastBootUpTime").ToString())
    Line 53: Response.Write("<br>")
    Line 54: Response.Write("<br>")

    Etant encore débutant en VB.NET je voulais savoir si quelqu'un pouvait m'aider un peux ?
    Un grand merci pour votre aide.
    Bien à vous.
    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
     
    <%@ Page Language="VB" %>
    <%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
    <%@ import Namespace="System.Data" %>
    <%@ import Namespace="System.Data.SqlClient" %>
    <%@ import Namespace="System.Web.Mail" %>
    <%@ import Namespace="System.IO" %>
    <%@ import Namespace="System.DirectoryServices" %>
    <%@ import Namespace="System.Configuration" %>
    <%@ import Namespace="System.Net" %>
    <%@ import Namespace="System" %>
    <%@ import Namespace="System.Net.DNS" %>
    <%@ import Namespace="System.ComponentModel" %>
    <%@ import Namespace="System.Management" %>
    <%@ import Namespace="System.Runtime.InteropServices" %>
    <%@ import Namespace="System" %>
    <%@ import Namespace="ActiveDs" %>
    <%@ import Namespace="System.Management.ConnectionOptions" %>
    <%@ import Namespace="System.Diagnostics.Process" %>
    <script runat="server">
     
        ' Insert page code here
        '
     
     
        Sub Button1_Click(sender As Object, e As EventArgs)
        Dim co As ConnectionOptions = New ConnectionOptions()
     
        With co
            .Impersonation = System.Management.ImpersonationLevel.Impersonate
            '* Use next line for XP
            .Authentication = System.Management.AuthenticationLevel.Packet
            '* Use next line for Win prior XP
            '.Authentication = System.Management.AuthenticationLevel.Connect
        End With
     
        co.Username = "toto"
        co.Password = "toto"
     
        Dim Ldap As DirectoryEntry = New DirectoryEntry("LDAP://scoot.local", "toto", "toto")
        Dim searcher As DirectorySearcher = New DirectorySearcher(Ldap)
        searcher.Filter = "(objectClass=computer)"
        Dim DirEntry As DirectoryEntry
     
         For Each result As SearchResult In searcher.FindAll
        DirEntry = result.GetDirectoryEntry
        Dim theScope As New ManagementScope("\\searcher.Filter\root\cimv2",co)
        Dim theQuery As New System.Management.ObjectQuery("SELECT * From Win32_OperatingSystem")
        Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
        Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
     
        'For Each currentResult As ManagementObject In theCollectionOfResults
             response.write("Drive:"& result("LastBootUpTime").ToString())
             Response.Write("<br>")
             Response.Write("<br>")
        Next
     
        Try
        Dim reboot As New ManagementObject("Win32_OperatingSystem")
                reboot.Get() ' throws ManagementException
                response.write("This shouldn't be displayed.")
     
                Catch e As ManagementException
     
                response.Write("ErrorCode :" & e.ErrorCode)
                response.Write("Message :" & e.Message)
                response.Write("Source :" & e.Source)
                If e.ErrorInformation != Nothing Then 'extended error object
                   response.Write("Extended Description : " & e.ErrorInformation("Description"))
                End If
            End Try
     
     
     
     
        End Sub
     
    </script>
    <html>
    <head>
    </head>
    <body>
        <form runat="server">
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </p>
            <p>
            </p>
            <p>
            </p>
            <p>
            </p>
            <p>
            </p>
            <p>
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
            </p>
            <!-- Insert content here -->
        </form>
    </body>
    </html>

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 208
    Par défaut
    Remplace :
    For Each result As SearchResult In searcher.FindAll
    par une boucle for avec index

  3. #3
    Membre confirmé
    Inscrit en
    Décembre 2006
    Messages
    158
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 158
    Par défaut
    Bonjour,
    quand je fais une boucle for avec index, j'obtient une erreur du genre :
    Compiler Error Message: BC30389: 'System.Data.SqlClient.Result' is not accessible in this context because it is 'Private'.

    Source Error:



    Line 45: 'For Each result As SearchResult In searcher.FindAll
    Line 46: For i= 0 to 75
    -->Line 47: DirEntry = result.GetDirectoryEntry
    Line 48: Dim theScope As New ManagementScope("\\searcher.Filter\root\cimv2",co)
    Line 49: Dim theQuery As New System.Management.ObjectQuery("SELECT * From Win32_OperatingSystem")

    Pourriez-vous me montrer un exemple s'il vous plait?
    Merci pour votre aide.
    Bien à vous.
    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
    105
     
    <%@ Page Language="VB" %>
    <%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
    <%@ import Namespace="System.Data" %>
    <%@ import Namespace="System.Data.SqlClient" %>
    <%@ import Namespace="System.Web.Mail" %>
    <%@ import Namespace="System.IO" %>
    <%@ import Namespace="System.DirectoryServices" %>
    <%@ import Namespace="System.Configuration" %>
    <%@ import Namespace="System.Net" %>
    <%@ import Namespace="System" %>
    <%@ import Namespace="System.Net.DNS" %>
    <%@ import Namespace="System.ComponentModel" %>
    <%@ import Namespace="System.Management" %>
    <%@ import Namespace="System.Runtime.InteropServices" %>
    <%@ import Namespace="System" %>
    <%@ import Namespace="ActiveDs" %>
    <%@ import Namespace="System.Management.ConnectionOptions" %>
    <%@ import Namespace="System.Diagnostics.Process" %>
    <script runat="server">
     
        ' Insert page code here
        '
     
     
        Sub Button1_Click(sender As Object, e As EventArgs)
        Dim i As integer
        Dim co As ConnectionOptions = New ConnectionOptions()
     
        With co
            .Impersonation = System.Management.ImpersonationLevel.Impersonate
            '* Use next line for XP
            .Authentication = System.Management.AuthenticationLevel.Packet
            '* Use next line for Win prior XP
            '.Authentication = System.Management.AuthenticationLevel.Connect
        End With
     
        co.Username = "toto"
        co.Password = "toto"
     
        Dim Ldap As DirectoryEntry = New DirectoryEntry("LDAP://scoot.local", "toto", "toto")
        Dim searcher As DirectorySearcher = New DirectorySearcher(Ldap)
        searcher.Filter = "(objectClass=computer)"
        Dim DirEntry As DirectoryEntry
     
         'For Each result As SearchResult In searcher.FindAll
         For i= 0 to 75
        DirEntry = result.GetDirectoryEntry
        Dim theScope As New ManagementScope("\\searcher.Filter\root\cimv2",co)
        Dim theQuery As New System.Management.ObjectQuery("SELECT * From Win32_OperatingSystem")
        Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
        Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
     
        'For Each currentResult As ManagementObject In theCollectionOfResults
             response.write("Drive:"& result("LastBootUpTime").ToString())
             Response.Write("<br>")
             Response.Write("<br>")
        Next
     
        Try
        Dim reboot As New ManagementObject("Win32_OperatingSystem")
                reboot.Get() ' throws ManagementException
                response.write("This shouldn't be displayed.")
     
                Catch e As ManagementException
     
                response.Write("ErrorCode :" & e.ErrorCode)
                response.Write("Message :" & e.Message)
                response.Write("Source :" & e.Source)
                If e.ErrorInformation != Nothing Then 'extended error object
                   response.Write("Extended Description : " & e.ErrorInformation("Description"))
                End If
            End Try
     
     
     
     
        End Sub
     
    </script>
    <html>
    <head>
    </head>
    <body>
        <form runat="server">
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </p>
            <p>
            </p>
            <p>
            </p>
            <p>
            </p>
            <p>
            </p>
            <p>
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
            </p>
            <!-- Insert content here -->
        </form>
    </body>
    </html>

  4. #4
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    J'ai l'impression que tu t'es un peu mélangé les pinceaux entre les objets WMI et Active Directory...
    "LastBootUpTime" doit être récupérée dans un ManagementObject (WMI), pas dans un SearchResult (AD)

Discussions similaires

  1. Réponses: 4
    Dernier message: 08/01/2012, 19h28
  2. VB6 - Problème de compilation avec un Objet - Run-Time Error 91
    Par Hadware dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 18/12/2008, 21h13
  3. [XSL] Problème d'accents avec l'objet Transformer
    Par djoule6 dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 15/04/2008, 19h19
  4. Problème avec l'objet FileSystemObject
    Par Poussy-Puce dans le forum ASP
    Réponses: 4
    Dernier message: 27/10/2005, 16h25
  5. [FLASH MX] Problème avec l'objet Date
    Par n_tony dans le forum Flash
    Réponses: 13
    Dernier message: 22/03/2005, 13h44

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