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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
<%@ 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" %>
<script runat="server">
' Insert page code here
'
Sub Button1_Click(sender As Object, e As EventArgs)
End Sub
Sub Page_Load()
AfficherListeClasses()
End Sub
Sub AfficherListeClasses()
'Try
'response.write("Button1_Click")
'lblError.Text = "abc" + 12
' Définition des objets
Dim oConnection As SqlConnection
Dim oCommand As SqlCommand
Dim oDataReader As SqlDataReader
Dim sSQL As String
Dim Ldap As DirectoryEntry = New DirectoryEntry("LDAP://tamac.local", "faratbi", "faratbi")
Dim searcher As DirectorySearcher = New DirectorySearcher(Ldap)
searcher.Filter = "(objectClass=computer)"
Dim DirEntry As DirectoryEntry
Dim largeInteger As Object
Dim lastLoggedOnDate As Date
Dim sqlString As String
'Création de notre connexion
oConnection = New SqlConnection()
'oConnection.ConnectionString = "server=CPQSQL2;database=PSPIntranet;uid=PSPIntranet;pwd=PSPIntranet;Max Pool Size=100000"
'pour l'authentification Windows mettre le paramettre Trusted_Connection=yes
oConnection.ConnectionString = "Server=127.0.0.1;Database=pspintranet;Trusted_Connection=yes"
' Ouverture de la connexion
oConnection.Open()
For Each result As SearchResult In searcher.FindAll
Dim IPHost As IPHostEntry = Dns.Resolve(DirEntry.Properties("Name").value)
Dim addressList As IPAddress() = IPHost.AddressList
Dim a As IPAddress = addressList(0) ' récupère la première adresse
largeInteger = DirEntry.Properties("lastLogOn").Value
lastLoggedOnDate = ConvertLargeIntToDate(largeInteger)
'Private Function ConvertLargeIntToDate(ByVal largeInteger As Object) As Date
'Dim typ As Type = largeInteger.GetType()
'Dim highPart As Integer = CInt(typ.InvokeMember("HighPart", Reflection.BindingFlags.GetProperty, Nothing, largeInteger, Nothing))
'Dim lowPart As Integer = CInt(typ.InvokeMember("LowPart", Reflection.BindingFlags.GetProperty, Nothing, largeInteger, Nothing))
'Dim fileTime As Int64 = Convert.ToInt64(highPart * (2 ^ 32))
'Return (DateTime.FromFileTime(fileTime))
'End Function
sqlString = " Insert Into Servers VALUES ("DirEntry.Properties("Name").value&","&a.ToString()&","&DateTime.FromFileTime(fileTime)&","&DirEntry.Properties("operatingSystemServicePack").value&","&DirEntry.Properties("operatingSystemVersion").value&","&DirEntry.Properties("operatingSystem").value&" ) "
'Ecriture de la requête SQL, extraction des data
sSQL = "SELECT * FROM Servers"
'Création de l'objet SqlCommand, execution de la requête
oCommand = New SqlCommand(sSQL, oConnection)
'Lecture des données
oDataReader = oCommand.ExecuteReader()
'Paramétrage du DataGrid
DTG_Liste_Classes.DataSource = oDataReader
DTG_Liste_Classes.DataBind()
' Fermeture du DataReader et de la connexion
oDataReader.Close()
oConnection.Close()
'End Try
Next
End Sub
Private Function ConvertLargeIntToDate(ByVal largeInteger As Object) As Date
Dim typ As Type = largeInteger.GetType()
Dim highPart As Integer = CInt(typ.InvokeMember("HighPart", Reflection.BindingFlags.GetProperty, Nothing, largeInteger, Nothing))
Dim lowPart As Integer = CInt(typ.InvokeMember("LowPart", Reflection.BindingFlags.GetProperty, Nothing, largeInteger, Nothing))
Dim fileTime As Int64 = Convert.ToInt64(highPart * (2 ^ 32))
Return (DateTime.FromFileTime(fileTime))
End Function
'Catch Ex As Exception
'lblError.Text =Ex.tostring
'response.write(Ex.tostring)
'End Try
'End Try
'End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:DataGrid id="DTG_Liste_Classes" runat="server"></asp:DataGrid>
</p>
<p>
</p>
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
</p>
<!-- Insert content here -->
</form>
</body>
</html> |
Partager