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;&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sp;<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
        </p>
        <!-- Insert content here -->
    </form>
</body>
</html>