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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
|
<%@ 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
'Dim datejour As Date
'datejour = Date.Now
SqlDataSourceControl1.ConnectionString="server='(local)'; trusted_connection=true; database='pspintranet'"
SqlDataSourceControl1.SelectCommand="Select nom_id,nom,Ip,(convert(varchar,datepart(dd,Reboot))+SPACE(1)+convert(varchar,datepart(mm,Reboot))+SPACE(1)+convert(varchar,datepart(yyyy,Reboot)))AS Reboot,ServicePack,OsVersion,OsName,FreeSpace_Go,(convert(varchar,datepart(dd,DateModif))+SPACE(1)+convert(varchar,datepart(mm,DateModif))+SPACE(1)+convert(varchar,datepart(yyyy,DateModif)))AS DateModif ,Total_Size_Go,Taille_Pourcentage,UserName from Servers where OsName not like '%Server%'"
For Each result As SearchResult In searcher.FindAll
DirEntry = result.GetDirectoryEntry
nom = DirEntry.Properties("Name").value
'insertion des ip dans la DB.
Dim IPHost As IPHostEntry = Dns.Resolve(DirEntry.Properties("Name").value)
Dim addressList As IPAddress() = IPHost.AddressList
Dim b As IPAddress = addressList(0) ' récupère la première adresse
Ip = b.ToString()
OsVersion = DirEntry.Properties("operatingSystemVersion").value
Os = DirEntry.Properties("operatingSystem").value
ServicePack = DirEntry.Properties("operatingSystemServicePack").value
Next
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 = "UPDATE Servers SET Reboot = '" & CheckReboot(TextBox1.Text) & "' where Ip = '" & TextBox1.Text & "'"
'SQLExecuteQueryConnect(Sql, SqlDataSourceControl1.ConnectionString)
'MxDataGrid1.DataBind()
'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
Function DiskSpace(ipadress As String)
Dim Unite As String
Dim TailleGO As Integer
Dim TailleMO As Integer
Dim TailleKO As Integer
Dim TailleO As Integer
Dim strSpace As String '= ""
Dim co As ConnectionOptions = New ConnectionOptions()
'Dim strSpace as String
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_LogicalDisk WHERE DeviceID ='c:' ")
Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
Try
Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
For Each Currentresult As ManagementObject In theCollectionOfResults
'If Unite = "o" Then
TailleGO = (currentResult("FreeSpace").ToString()/ 1073741824) ' Nombre de Giga Octets
'Else
'TailleGO = (currentResult("FreeSpace") / 1048576) ' Nombre de Giga Octets
'End If
'TailleMO = (TailleGO - Int(TailleGO)) * 1024 ' Nombre de Mega Octets
'TailleKO = (TailleMO - Int(TailleMO)) * 1024 ' Nombre de Kilo Octets
'If Unite = "o" Then
'TailleO = (TailleKO - Int(TailleKO)) * 1024 ' Nombre d'Octets
'End If
strSpace = TailleGO
'strSpace = ("MO:" & TailleMO)
'strSpace = TailleKO
'If Unite = "o" Then
'strSpace = TailleO
'End If
Next
Catch com_ex As System.Runtime.InteropServices.COMException When com_ex.ErrorCode = &H800706BA
Catch ua_ex As System.UnauthorizedAccessException
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 strSpace
End Function
'Function DiskSpace(ipadress As String)
'Dim co As ConnectionOptions = New ConnectionOptions()
'Dim strSpace as String
'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_LogicalDisk WHERE DeviceID ='c:' ")
'Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
'Try
'Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
'For Each currentResult As ManagementObject In theCollectionOfResults
'strSpace = (currentResult("FreeSpace").ToString()/1073741824 )
'Next
' End
'Catch com_ex As System.Runtime.InteropServices.COMException When com_ex.ErrorCode = &H800706BA
'Catch ua_ex As System.UnauthorizedAccessException
'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 strSpace
'End Function
Function DateUpdate(ipadress As String)
Dim co As ConnectionOptions = New ConnectionOptions()
Dim i As integer
Dim strDateUpdate as String
Dim TestConnection As Boolean
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
strDateUpdate = Left(currentResult("LocalDateTime").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 strDateUpdate
End Function
Function TotalSize(ipadress As String)
Dim co As ConnectionOptions = New ConnectionOptions()
Dim i As integer
Dim strTotalSize as String
Dim TestConnection As Boolean
Dim TailleGO As Integer
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 Size From Win32_LogicalDisk where DeviceID = 'c:' ")
Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
Try
Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
For Each currentResult As ManagementObject In theCollectionOfResults
TailleGO = (currentResult("Size").ToString()/ 1073741824)
strTotalSize = TailleGO
'strTotalsize = (currentResult("Size").ToString()/1048576)
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 strTotalSize
End Function
Function TaillePourcent(ipadress As String)
Dim co As ConnectionOptions = New ConnectionOptions()
Dim i As integer
Dim strTotalSizePc1 as Integer
Dim TestConnection As Boolean
Dim TailleGO As Integer
Dim TailleGO1 As Integer
Dim UsedSpace As Integer
Dim strTotalSizePc As String
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 FreeSpace, Size From Win32_LogicalDisk where DeviceID = 'c:' ")
Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
Try
Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
For Each currentResult As ManagementObject In theCollectionOfResults
TailleGO = (currentResult("Size").ToString()/ 1073741824)
'strTotalSize = TailleGO
TailleGO1 = (currentResult("FreeSpace").ToString()/ 1073741824)
UsedSpace = (TailleGO-TailleGO1)
strTotalSizePc1 = ((UsedSpace/TailleGO)*100)
strTotalSizePc = strTotalSizePc1
'strTotalsize = (currentResult("Size").ToString()/1048576)
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 strTotalSizePc
End Function
Function name(ipadress As String)
Dim co As ConnectionOptions = New ConnectionOptions()
Dim TestConnection As Boolean
Dim nom As String
Dim strTotalSizePc As String
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 UserName From Win32_ComputerSystem ")
Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
Try
Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
For Each currentResult As ManagementObject In theCollectionOfResults
nom = currentResult("UserName").ToString()
strTotalSizePc = nom
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 strTotalSizePc
End Function
Sub MxDataGrid1_ItemDataBound(sender As Object, e As MxDataGridItemEventArgs)
lblError.Text = ""
End Sub
Sub MxDataGrid1_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim datejour As DateTime
datejour = Date.Now
Dim IpAdress AS String
IpAdress = MxDataGrid1.SelectedItem.Cells(3).Text
Dim Sql As String
Dim nom As String
nom = MxDataGrid1.SelectedItem.Cells(2).Text
Sql = "UPDATE Servers SET Reboot = '" & CheckReboot(IpAdress) & "', FreeSpace_Go = '" & DiskSpace(IpAdress) & "',DateModif = '" & DateUpdate(IpAdress) & "',Total_Size_Go = '" & TotalSize(Ipadress) &"', Taille_Pourcentage = '" & TaillePourcent(Ipadress) & "%" & "', UserName = '" & name(Ipadress) & "' where Ip = '" & IpAdress & "'"
SQLExecuteQueryConnect(Sql, SqlDataSourceControl1.ConnectionString)
'update de la table évolution
Sql = "UPDATE Evolution SET DateModif = '" & DateUpdate(IpAdress) & "', FreeSpace_Go = '" & DiskSpace(IpAdress) & "' where nom = '" & nom & "'"
SQLExecuteQueryConnect(Sql, SqlDataSourceControl1.ConnectionString)
MxDataGrid1.DataBind()
lblError.Text = "Update for : " & IpAdress
End Sub
Sub MxDataGrid1_SelectedIndexChanged(sender As Object, e As EventArgs)
Response.Redirect("helpdesk.aspx")
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<wmx:SqlDataSourceControl id="SqlDataSourceControl1" runat="server" DeleteCommand="" UpdateCommand=""></wmx:SqlDataSourceControl>
<wmx:MxDataGrid id="MxDataGrid1" runat="server" OnSelectedIndexChanged="MxDataGrid1_SelectedIndexChanged" OnItemDataBound="MxDataGrid1_ItemDataBound" AllowPaging="True" AllowSorting="True" CellPadding="3" DataKeyField="nom_id" DataSourceControlID="SqlDataSourceControl1" DataMember="Servers" BackColor="White" BorderColor="#CCCCCC" BorderWidth="1px" BorderStyle="None">
<FooterStyle backcolor="White" forecolor="#000066"></FooterStyle>
<SelectedItemStyle backcolor="#669999" font-bold="True" forecolor="White"></SelectedItemStyle>
<PagerStyle mode="NumericPages" horizontalalign="Center" backcolor="White" forecolor="#000066"></PagerStyle>
<ItemStyle forecolor="#000066"></ItemStyle>
<Fields>
<wmx:ButtonField Text="Select" DataTextField="nom_id" CommandName="Select" DataTextFormatString="Update"></wmx:ButtonField>
<wmx:ButtonField Text="Select" DataTextField="nom_id" CommandName="Select" DataTextFormatString="Applications"></wmx:ButtonField>
</Fields>
<HeaderStyle backcolor="#006699" font-bold="True" forecolor="White"></HeaderStyle>
</wmx:MxDataGrid>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<!-- Insert content here --><asp:Label id="lblError" runat="server"></asp:Label>
</form>
</body>
</html> |