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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
<%@ 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.Text" %>
<%@ import Namespace="System.Net.NetworkInformation" %>
<%@ import Namespace="System.Net.Sockets" %>
<script runat="server">
' Gestion des users
'
Sub Page_Load()
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
Dim nom As String
Dim OsVersion As String
Dim Os As String
Dim ServicePack As String
Dim Ip As String
Dim largeInteger As Object
Dim lastLoggedOnDate As Date
Dim reboot As Date
Dim rebootTime As Object
SqlDataSourceControl1.ConnectionString="server='(local)'; trusted_connection=true; database='pspintranet'"
SqlDataSourceControl1.SelectCommand="Select * from Servers where OsName not like '%Server%'"
MxDataGrid1.DataBind()
End Sub
Function SQLExecuteQueryConnect(ByVal sqlQuery As String, sqlConnect as String) As String
Dim a As String
' CREER LA CONNEXION
Dim objConnect As New SqlConnection(sqlConnect)
objConnect.Open()
' CREER LA COMMANDE
Dim objCommand As New SqlCommand(sqlQuery, objConnect)
' EXECUTER LA COMMANDE
a = objCommand.ExecuteNonQuery()
Return a
End Function
'Ici ce fait l'update
Sub Button1_Click(sender As Object, e As EventArgs)
Dim Sql As String
'Sql = "INSERT INTO Servers (Reboot) VALUES ('" & CheckReboot(TextBox1.Text) & "') where Ip = '" & TextBox1.Text & "'"
Sql = "UPDATE Servers SET Reboot = '" & CheckReboot(TextBox1.Text) & "' where Ip = '" & TextBox1.Text & "'"
SQLExecuteQueryConnect(Sql, SqlDataSourceControl1.ConnectionString)
End Sub
Function CheckReboot(ipadress as String)
Dim co As ConnectionOptions = New ConnectionOptions()
Dim i As integer
Dim strDate as String
Dim TestConnection As Boolean
'Dim Ip As String
'Ip = "192.168.1.170"
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 theScope As New ManagementScope("\\" & ipadress & "\root\cimv2",co)
Dim theQuery As New System.Management.ObjectQuery("SELECT * From Win32_OperatingSystem ")
Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
Try
Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
For Each currentResult As ManagementObject In theCollectionOfResults
strDate = Left(currentResult("LastBootUpTime").ToString(),8)
Next
Catch com_ex As System.Runtime.InteropServices.COMException When com_ex.ErrorCode = &H800706BA
'Response.write("Machines are unvailable:" & ipadress &"It may be off line or the firewallsettings are preventing the connection")
Catch ua_ex As System.UnauthorizedAccessException
' Response.write("The Remote PC refused the connection This is most likely due to a permissions issue.")
'Catch wmi_ex As Exception When wmi_ex.Exception = Management.ManagementStatus.AccessDenied
'Response.write("You do not have sufficient privileges on the remote PC:" & ipadress)
Catch ex As Exception
If IsNothing(ex.InnerException) Then
Response.write("Could not get initial data")
Else
Response.write("Could not get initial data:" & ex.InnerException.Message)
End if
End Try
return strDate
End Function
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<wmx:SqlDataSourceControl id="SqlDataSourceControl1" runat="server" UpdateCommand="" DeleteCommand=""></wmx:SqlDataSourceControl>
<wmx:MxDataGrid id="MxDataGrid1" runat="server" BorderStyle="None" BorderWidth="1px" BorderColor="#CCCCCC" BackColor="White" DataMember="Servers" DataSourceControlID="SqlDataSourceControl1" DataKeyField="nom_id" CellPadding="3" AllowSorting="True" AllowPaging="True">
<FooterStyle backcolor="White" forecolor="#000066"></FooterStyle>
<HeaderStyle backcolor="#006699" font-bold="True" forecolor="White"></HeaderStyle>
<ItemStyle forecolor="#000066"></ItemStyle>
<PagerStyle mode="NumericPages" horizontalalign="Center" backcolor="White" forecolor="#000066"></PagerStyle>
<SelectedItemStyle backcolor="#669999" font-bold="True" forecolor="White"></SelectedItemStyle>
</wmx:MxDataGrid>
</p>
<p>
</p>
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Update"></asp:Button>
</p>
<!-- Insert content here -->
</form>
</body>
</html> |
Partager