IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

[VBS] Organiser la sortie d'un script dans un table SQL


Sujet :

VBScript

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Inscrit en
    Septembre 2007
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Septembre 2007
    Messages : 3
    Par défaut [VBS] Organiser la sortie d'un script dans un table SQL
    Bonjour,

    J'ai fait un script qui permet de faire des requetes SQL et d'ecrire les resultats dans une base SQL.

    Code:



    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
    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 "
    Le probleme que je rencontre est lié à l'affichage dans la base SQL(cf fichier joint). En effet l'utilisation de "objRS.AddNew" me decalle tout d'une ligne à partir du moment ou j'ai plusieurs entrées? Par exemple deux entrées pour CPU.
    Comment pourrai je faire pour eviter ce decallage et eviter ainsi des cases NULL?
    Images attachées Images attachées  

Discussions similaires

  1. Script d'import d'un fichier XML dans une table SQL-Server
    Par thiersco dans le forum Développement
    Réponses: 2
    Dernier message: 26/11/2013, 09h45
  2. Mots clés dans une table sql
    Par vince_grenoblois dans le forum Langage SQL
    Réponses: 1
    Dernier message: 01/08/2006, 14h21
  3. Réponses: 3
    Dernier message: 07/06/2006, 12h05
  4. Réponses: 7
    Dernier message: 02/05/2006, 11h28
  5. Réponses: 7
    Dernier message: 27/01/2006, 15h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo