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
| 'Constant and variable
Const ForReading = 1, ForWriting = 2, ForAppending = 8
BDD="Audit_sec"
ServeurSQL = "SRV"
' Import data to sql database
'==========================================================================
'Connexion à la BDD
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
ChaineCnx="Provider=sqloledb;Data Source=" & ServeurSQL & ";Initial Catalog=" & BDD & ";User Id=auditsec;Password=audit2007;"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
objConn.Open ChaineCnx
objRS.CursorLocation = 3
objRS.Open "SELECT * FROM audit_test" , objConn, 3, 3
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
''************************
''Time zone information
Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone",,48)
For Each objItem in colItems
objRS.AddNew
objRS("tm_zone") = objItem.Caption
objRS("tm_daylight") = objItem.DaylightName
objRS.Update
Next
''************************
''System information
Set colItems = objWMIService.ExecQuery("Select * FROM Win32_ComputerSystem",,48)
For Each objItem in colItems
'objRS.AddNew
objRS("ComputerName") = objItem.Caption
objRS("UserName") = objItem.UserName
wscript.echo "UserName:" & objItem.UserName
objRS("Model") = objItem.Model
wscript.echo "Model:" & objItem.Model
objRS.Update
Next
''************************
''Get Network details
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
objRS("Description") = objItem.Description
wscript.echo "Description:" & objItem.Description
objRS("MACAddress") = objItem.MACAddress
wscript.echo "MACAddress:" & objItem.MACAddress
objRS("IPaddress") = objItem.IPAddress(i)
'Wscript.echo "Ipaddress:" & objItem.IPAddress
objRS("DNSDomain") = objItem.DNSDomain
wscript.echo "DNSDomain:" & objItem.DNSDomain
objRS.Update
Next
''****************
'' Get OS Details
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem In colItems
objRS("OS") = objItem.Name
'objRS("pos") = InStr(1, cOsS,"|",1)
'objRS("cOS1 = left(cOSs,pos-1)
wscript.echo "OS: " & cOS1 & " " & objItem.CSDVersion
objRS("Service pack") = objItem.CSDVersion
objRS("Memory") = FormatNumber(objItem.TotalVisibleMemorySize/1024,0)
objRS.Update
Next
''****************
''Get BIOS Details
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem In colItems
objRS("SerialNumber") = objItem.SerialNumber
wscript.echo "SerialNumber: " & objItem.SerialNumber
objRS.Update
Next
''**********************************
''Get PROCESSOR Details
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)
For Each objItem in colItems
objRS.AddNew
objRS("CPU") = objItem.Name
objRS("CurrentClockSpeed") = objItem.CurrentClockSpeed & " MHz"
wscript.echo "CPU: " & trim(objItem.Name) & " " & objItem.CurrentClockSpeed & " MHz"
objRS.Update
Next
''**************************************
''Get optical drive
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive",,48)
For Each objItem in colItems
objRS.AddNew
objRS("CD Drive") = objItem.Drive
wscript.echo "CD Drive:" & objItem.Drive
objRS("Optical Drive") = objItem.Caption
wscript.echo "Optical Drive:" & objItem.Caption
objRS.Update
Next
''**************************************
''Get Disk Details
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive",,48)
For Each objItem in colItems
objRS.AddNew
objRS("Disk") = objItem.Caption
wscript.echo "Disk:" & objItem.Caption
objRS("ndisktype") = objItem.InterfaceType
objRS("Size") = (objItem.Size /1024 /1024)
objRS.Update
Next
''**************************************
''Get partition information
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskPartition",,48)
For Each objItem in colItems
objRS.AddNew
objRS("deviceId") = objItem.DeviceID
objRS("diskindex") = objItem.DiskIndex
objRS.Update
Next
''**************************************
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where DriveType=3")
For Each objItem in colItems
objRS.AddNew
objRS("Partition") =objItem.Caption
objRS("FreeSpace") = (objItem.FreeSpace /1024 /1024)
objRS("Volumename") =objItem.VolumeName
objRS.Update
Next
''**************************************
''Get softwares Details
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Product")
For Each objItem in colItems
objRS.AddNew
objRS("Softwares")= objItem.Caption
objRS("Versions")= objItem.Version
objRS.Update
Next
objRS.Close
objConn.Close
Wscript.Echo "Finished " |
Partager