2009-08-01 8 views
0

Vous rencontrez un problème avec ce code ici; Je n'arrive pas à comprendre ce qui ne va pas.WMI/VBS/HTML Script d'informations système

Toutes les autres variables semblent bien imprimer dans la sortie HTML; mais j'obtiens une erreur qui se rapporte à la variable cputype.

je reçois l'erreur suivante

C:\Users\Methical\Desktop\sysinfo.vbs(235,1) Microsoft VBScript runtime error: Invalid procedure call or argument

Je pense qu'il a quelque chose à voir avec cette ligne ici

fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>CPU</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & cputype & "</i></td></tr>" 

Si je supprime cette ligne; le script compile et sort sans erreur.

Voici le code complet ci-dessous

Dim strComputer, objWMIService, propValue, objItem 
Dim strUserName, strPassword, colItems, SWBemlocator 

' This section queries for the workstation to be scanned. 
UserName = "" 
Password = "" 
strComputer = "127.1.1.1" 
ImgDir = "C:\Scripts\images\" 

'Sets up the connections and opjects to be used throughout the script. 
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator") 
Set objWMIService = SWBemlocator.ConnectServer(,"root\CIMV2",strUserName,strPassword) 

'This determines the current date and time of the PC being scanned. 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LocalTime", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) 
For Each objItem in colItems 
    If objItem.Minute < 10 Then 
     theMinutes = "0" & objItem.Minute 
    Else 
     theMinutes = objItem.Minute 
    End If 
    If objItem.Second < 10 Then 
     theSeconds = "0" & objItem.Second 
    Else 
     theSeconds = objItem.Second 
    End If 
    DateTime = objItem.Month & "/" & objItem.Day & "/" & objItem.Year & " - " & objItem.Hour & ":" & theMinutes & ":" & theSeconds 
Next 

'Gets some ingomation about the Operating System including Service Pack level. 
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48) 
For Each objItem in colItems 
    WKID = objItem.CSName 
    WKOS = objItem.Caption 
    CSD = objItem.CSDVersion 
    Architecture = objItem.OSArchitecture 
    SysDir = objItem.SystemDirectory 
    SysDrive = objItem.SystemDrive 
    WinDir = objItem.WindowsDirectory 
    ServicePack = objItem.ServicePackMajorVersion & "." & objItem.ServicePackMinorVersion 
Next 

'This section returns the Time Zone 
Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone") 
For Each objItem in colItems 
    Zone = objItem.Description 
Next 

'This section displays the Shadow Storage information 
Set colItems = objWMIService.ExecQuery("Select * from Win32_ShadowStorage") 
For Each objItem in colItems 
    Allocated = int((objItem.AllocatedSpace/1024)/1024+1) 
    UsedSpace = int((objItem.UsedSpace/1024)/1024+1) 
    MaxSpace = int((objItem.MaxSpace/1024)/1024+1) 
Next 

'This section returns the InstallDate of the OS 
Set objSWbemDateTime = _ 
    CreateObject("WbemScripting.SWbemDateTime") 
Set colOperatingSystems = _ 
    objWMIService.ExecQuery _ 
    ("Select * from Win32_OperatingSystem") 
For Each objOperatingSystem _ 
    in colOperatingSystems 
    objSWbemDateTime.Value = _ 
     objOperatingSystem.InstallDate 
    InstallDate = _ 
     objSWbemDateTime.GetVarDate(False) 
Next 

'This section returns the Video card and current resolution. 
Set colItems = objWMIService.ExecQuery("Select * from Win32_DisplayConfiguration",,48) 
For Each objItem in colItems 
    VideoCard = objItem.DeviceName 
    Resolution = objItem.PelsWidth & " x " & objItem.PelsHeight & " x " & objItem.BitsPerPel & " bits" 
Next 

'This section returns the Video card memory. 
Set objWMIService = GetObject("winmgmts:root\cimv2") 
Set colItems = objWMIService.ExecQuery ("Select * from Win32_VideoController") 
For Each objItem in colItems 
    VideoMemory = objItem.AdapterRAM/1024/1024 
Next 

'This returns various system information including current logged on user, domain, memory, manufacture and model. 
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48) 
For Each objItem in colItems 
    UserName = objItem.UserName 
    Domain = objItem.Domain 
    TotalMemory = int((objItem.TotalPhysicalMemory/1024)/1024+1) 
    Manufacturer = objItem.Manufacturer 
    Model = objItem.Model 
    SysType = objItem.SystemType 
Next 

'This determines the total hard drive space and free hard drive space. 
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where Name='C:'",,48) 
For Each objItem in colItems 
    FreeHDSpace = Fix(((objItem.FreeSpace/1024)/1024)/1024) 
    TotalHDSpace = Fix(((objItem.Size/1024)/1024)/1024) 
Next 

'This section returns the default printer and printer port. 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer where Default=True", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) 
For Each objItem in colItems 
    Printer = objItem.Name 
    PortName = objItem.PortName 
Next 

'This returns the CPU information. 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) 
For Each objItem in colItems 
    CPUDesc = LTrim(objItem.Name) 
Next 


'// CPU Info 
For each objCPU in GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2").InstancesOf("Win32_Processor") 
       Select Case objCPU.Family 
        Case 2 
         cputype = "Unknown" 
        Case 11 
         cputype = "Pentium brand" 
        Case 12 
         cputype = "Pentium Pro" 
        Case 13 
         cputype = "Pentium II" 
        Case 14 
         cputype = "Pentium processor with MMX technology" 
        Case 15 
         cputype = "Celeron " 
        Case 16 
         cputype = "Pentium II Xeon" 
        Case 17 
         cputype = "Pentium III" 
        Case 28 
         cputype = "AMD Athlon Processor Family" 
        Case 29 
         cputype = "AMD Duron Processor" 
        Case 30 
         cputype = "AMD2900 Family" 
        Case 31 
         cputype = "K6-2+" 
        Case 130 
         cputype = "Itanium Processor" 
        Case 176 
         cputype = "Pentium III Xeon" 
        Case 177 
         cputype = "Pentium III Processor with Intel SpeedStep Technology" 
        Case 178 
         cputype = "Pentium 4" 
        Case 179 
         cputype = "Intel Xeon" 
        Case 181 
         cputype = "Intel Xeon processor MP" 
        Case 182 
         cputype = "AMD AthlonXP Family" 
        Case 183 
         cputype = "AMD AthlonMP Family" 
        Case 184 
         cputype = "Intel Itanium 2" 
        Case 185 
         cputype = "AMD Opteron Family" 
       End Select 
Next 

'This returns the current uptime (time since last reboot) of the system. 
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") 
For Each objOS in colOperatingSystems 
    dtmBootup = objOS.LastBootUpTime 
    dtmLastBootupTime = WMIDateStringToDate(dtmBootup) 
    dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now) 
    Uptime = dtmSystemUptime 
Next 
Function WMIDateStringToDate(dtmBootup) 
    WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) & " " & Mid (dtmBootup, 9, 2) & ":" & Mid(dtmBootup, 11, 

2) & ":" & Mid(dtmBootup,13, 2)) 
End Function 

dim objFSO 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

' -- The heart of the create file script ----------------------- 
' -- Creates the file using the value of strFile on Line 11 
' -------------------------------------------------------------- 
Set fileOutput = objFSO.CreateTextFile("x.html", true) 

'Set fileOutput = objExplorer.Document 

'This is the code for the web page to be displayed. 

fileOutput.WriteLine "<html>" 
fileOutput.WriteLine " <head>" 
fileOutput.WriteLine "  <title>System Information for '" & WKID & "' </title>" 
fileOutput.WriteLine " </head>" 
fileOutput.WriteLine " <body bgcolor='#FFFFFF' text='#000000' link='#0000FF' vlink='000099' alink='#00FF00'>" 
fileOutput.WriteLine "  <center>" 
fileOutput.WriteLine "   <h1>System Information for " & WKID & "</h1>" 
fileOutput.WriteLine "   <table border='0' cellspacing='1' cellpadding='1' width='95%'>" 
fileOutput.WriteLine "    <tr><td background='" & ImgDir & "blue_spacer.gif'>" 
fileOutput.WriteLine "     <table border='0' cellspacing='0' cellpadding='0' width='100%'>" 
fileOutput.WriteLine "      <tr><td>" 
fileOutput.WriteLine "       <table border='0' cellspacing='0' cellpadding='0' width='100%'>" 
fileOutput.WriteLine "        <tr>" 
fileOutput.WriteLine "         <td width='5%' align='left' valign='middle' background='" & ImgDir & "blue_spacer.gif'><img src='" & ImgDir & 

"write.gif'></td>" 
fileOutput.WriteLine "         <td width='95%' align='left' valign='middle' background='" & ImgDir & "blue_spacer.gif'> <font 

color='#FFFFFF' size='5'>WKInfo - </font><font color='#FFFFFF' size='3'>General information on the Workstation.</font></td>" 
fileOutput.WriteLine "        </tr>" 
fileOutput.WriteLine "        <tr><td colspan='2' bgcolor='#FFFFFF'>" 
fileOutput.WriteLine "         <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' 

bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
    fileOutput.WriteLine"            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Date and Time</h3></b></TD></TR>" 
    fileOutput.WriteLine"            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Date/Time</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & DateTime & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Uptime</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & Uptime & " hours</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Time Zone</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & Zone & " </i></td></tr>" 
    fileOutput.WriteLine"            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Computer 

Information</h3></b></TD></TR>" 
    fileOutput.WriteLine"            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Manufacturer</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & Manufacturer & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Model</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & Model & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Based</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & SysType & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Operating System</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & WKOS & " " & CSD & " " & Architecture & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Operating System Install Date</TD><td width='70%' 

bgcolor=#f0f0f0 align=left><i>" & InstallDate & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>UserName</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & UserName & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Workstation Name</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & WKID & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Domain</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & Domain & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Drive</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & SysDrive & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Directory</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & SysDir & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Windows Directory</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & WinDir & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Allocated Space</TD><td width='70%' 

bgcolor=#f0f0f0 align=left><i>" & Allocated & " MB</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Used Space</TD><td width='70%' 

bgcolor=#f0f0f0 align=left><i>" & UsedSpace & " MB</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Max Space</TD><td width='70%' 

bgcolor=#f0f0f0 align=left><i>" & MaxSpace & " MB</i></td></tr>" 
    fileOutput.WriteLine"            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Hardware 

Information</h3></b></TD></TR>" 
    fileOutput.WriteLine"            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>CPU</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & cputype & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Memory</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & TotalMemory & " MB</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Total HDD Space</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & TotalHDSpace & " GB</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Free HDD Space</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & FreeHDSpace & " GB</i></td></tr>" 
    fileOutput.WriteLine"            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Video Card 

Information</h3></b></TD></TR>" 
    fileOutput.WriteLine"            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Video Card</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & VideoCard & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Resolution</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & Resolution & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Memory</TD><td width='70%' bgcolor=#f0f0f0 

align=left><i>" & VideoMemory & " MB</i></td></tr>" 
'This section lists all the current services and their status. 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Current Service 

Information</h3></b></TD></TR>" 
fileOutput.WriteLine "          <tr><td colspan='2' bgcolor='#f0f0f0'>" 
fileOutput.WriteLine "           <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' 

bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
fileOutput.WriteLine "            <TR><TD width='70%' align='center' bgcolor='#e0e0e0'><b>Service Name</b></td><TD width='30%' 

align='center' bgcolor='#e0e0e0'><b>Service State</b></td><tr>" 
Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service") 
For Each objService in colRunningServices 
fileOutput.WriteLine "           <TR><TD align='left' bgcolor='#f0f0f0'>" & objService.DisplayName & "</TD><td bgcolor=#f0f0f0 

align=center><i>" & objService.State & "</i></td></tr>" 
    wscript.echo "           <TR><TD align='left' bgcolor='#f0f0f0'>" & objService.DisplayName & "</TD><td bgcolor=#f0f0f0 

align=center><i>" & objService.State & "</i></td></tr>" 
Next 
fileOutput.WriteLine "           </table>" 
fileOutput.WriteLine "          </td></tr>" 
'This section lists all the current running processes and some information. 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Current Process 

Information</h3></b></TD></TR>" 
fileOutput.WriteLine "          <tr><td colspan='2' bgcolor='#f0f0f0'>" 
fileOutput.WriteLine "           <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' 

bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
fileOutput.WriteLine "            <TR><TD width='10%' align='center' bgcolor='#e0e0e0'><b>PID</b></td><TD width='35%' 

align='center' bgcolor='#e0e0e0'><b>Process Name</b></td><TD width='40%' align='center' bgcolor='#e0e0e0'><b>Owner</b></td><TD width='15%' align='center' 

bgcolor='#e0e0e0'><b>Memory</b></td></tr>" 
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process") 
For Each objProcess in colProcessList 
colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain) 
fileOutput.WriteLine "            <TR><TD align='center' bgcolor='#f0f0f0'>" & objProcess.Handle & "</td><TD align='center' 

bgcolor='#f0f0f0'>" & objProcess.Name & "</td><TD align='center' bgcolor='#f0f0f0'>" & strUserDomain & "\" & strNameOfUser & "</td><TD align='center' 

bgcolor='#f0f0f0'>" & objProcess.WorkingSetSize/1024 & " kb</td><tr>" 
Next 
fileOutput.WriteLine "           </table>" 
fileOutput.WriteLine "          </td></tr>" 
'This section lists all the currently installed software on the machine. 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Installed Software</i></b></TD></TR>" 
fileOutput.WriteLine "          <tr><td colspan='2' bgcolor='#f0f0f0'>" 
Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product") 
For Each objSoftware in colSoftware 
    fileOutput.WriteLine"           <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' 

bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
    fileOutput.WriteLine"            <tr><td width=30% align=center bgcolor='#e0e0e0'><b>Name</b></td><td width=30% align=center 

bgcolor='#e0e0e0'><b>Vendor</b></td><td width=30% align=center bgcolor='#e0e0e0'><b>Version</b></td></tr>" 
    fileOutput.WriteLine"            <tr><td align=center bgcolor=#f0f0f0>" & objSoftware.Name & "</td><td align=center 

bgcolor=#f0f0f0>" & objSoftware.Vendor & "</td><td align=center bgcolor=#f0f0f0>" & objSoftware.Version & "</td></tr>" 
    fileOutput.WriteLine"            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
    fileOutput.WriteLine"           </table>" 
Next 
fileOutput.WriteLine "          </td></tr>" 
fileOutput.WriteLine "         </table>" 
fileOutput.WriteLine "        </td></tr>" 
fileOutput.WriteLine "       </table>" 
fileOutput.WriteLine "      </td></tr>" 
fileOutput.WriteLine "     </table>" 
fileOutput.WriteLine "    </td></tr>" 
fileOutput.WriteLine "   </table>" 
fileOutput.WriteLine "   <p><small></small></p>" 
fileOutput.WriteLine "  </center>" 
fileOutput.WriteLine " </body>" 
fileOutput.WriteLine "<html>" 
fileOutput.close 
WScript.Quit 

Répondre

0

cputype est hors de portée où vous essayez d'écrire en HTML. Il est d'abord utilisé à l'intérieur de l'instruction select case, il est donc hors de portée en dehors de cette instruction select.

Une bonne pratique serait de déclarer explicitement toutes vos variables et de démarrer votre script avec l'option explicite et l'option stricte pour éviter ce type de situation.

+0

Bravo pour votre contribution David. Je suis connu pour .vbs, et je ne le sais pas très bien. J'ai mis cela ensemble à partir de quelques sources que j'ai trouvées sur le net; mais n'a pas pu obtenir la variable cputype à afficher. J'ai essayé ce que vous avez dit; et mettez l'option explicite en haut puis utilisez 'dim' pour déclarer toutes les variables. Toujours obtenir un champ vide où le cputype doit être affiché .. –

+0

OK. Avez-vous déclaré la variable au début du fichier? J'ai une autre suggestion. A la fin de votre "Select Case" mettre dans un Case Else et définir la variable à quelque chose d'évident comme "Je n'ai pas pensé à celui-ci" De cette façon, s'il n'y a pas de correspondance dans les autres déclarations de cas, vous, Je vais l'attraper de cette façon. – David

0

J'ai essayé cela; et n'a toujours pas fonctionné. Déclarée @ le début, a ajouté le Case Else @ la fin de la structure Select Case ..

Dim strComputer, objWMIService, propValue, objItem 
Dim strUserName, strPassword, colItems, SWBemlocator 
Dim cputype 

' This section queries for the workstation to be scanned. 
UserName = "" 
Password = "" 
strComputer = "127.1.1.1" 
ImgDir = "C:\Scripts\images\" 

'Sets up the connections and opjects to be used throughout the script. 
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator") 
Set objWMIService = SWBemlocator.ConnectServer 

(,"root\CIMV2",strUserName,strPassword) 

'This determines the current date and time of the PC being scanned. 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LocalTime", 

"WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) 
For Each objItem in colItems 
    If objItem.Minute < 10 Then 
     theMinutes = "0" & objItem.Minute 
    Else 
     theMinutes = objItem.Minute 
    End If 
    If objItem.Second < 10 Then 
     theSeconds = "0" & objItem.Second 
    Else 
     theSeconds = objItem.Second 
    End If 
    DateTime = objItem.Month & "/" & objItem.Day & "/" & objItem.Year & " 

- " & objItem.Hour & ":" & theMinutes & ":" & theSeconds 
Next 

'Gets some ingomation about the Operating System including Service Pack 

level. 
Set colItems = objWMIService.ExecQuery("Select * from 

Win32_OperatingSystem",,48) 
For Each objItem in colItems 
    WKID = objItem.CSName 
    WKOS = objItem.Caption 
    CSD = objItem.CSDVersion 
    Architecture = objItem.OSArchitecture 
    SysDir = objItem.SystemDirectory 
    SysDrive = objItem.SystemDrive 
    WinDir = objItem.WindowsDirectory 
    ServicePack = objItem.ServicePackMajorVersion & "." & 

objItem.ServicePackMinorVersion 
Next 

'This section returns the Time Zone 
Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone") 
For Each objItem in colItems 
    Zone = objItem.Description 
Next 

'This section displays the Shadow Storage information 
Set colItems = objWMIService.ExecQuery("Select * from 

Win32_ShadowStorage") 
For Each objItem in colItems 
    Allocated = int((objItem.AllocatedSpace/1024)/1024+1) 
    UsedSpace = int((objItem.UsedSpace/1024)/1024+1) 
    MaxSpace = int((objItem.MaxSpace/1024)/1024+1) 
Next 

'This section returns the InstallDate of the OS 
Set objSWbemDateTime = _ 
    CreateObject("WbemScripting.SWbemDateTime") 
Set colOperatingSystems = _ 
    objWMIService.ExecQuery _ 
    ("Select * from Win32_OperatingSystem") 
For Each objOperatingSystem _ 
    in colOperatingSystems 
    objSWbemDateTime.Value = _ 
     objOperatingSystem.InstallDate 
    InstallDate = _ 
     objSWbemDateTime.GetVarDate(False) 
Next 

'This section returns the Video card and current resolution. 
Set colItems = objWMIService.ExecQuery("Select * from 

Win32_DisplayConfiguration",,48) 
For Each objItem in colItems 
    VideoCard = objItem.DeviceName 
    Resolution = objItem.PelsWidth & " x " & objItem.PelsHeight & " x " & 

objItem.BitsPerPel & " bits" 
Next 

'This section returns the Video card memory. 
Set objWMIService = GetObject("winmgmts:root\cimv2") 
Set colItems = objWMIService.ExecQuery ("Select * from 

Win32_VideoController") 
For Each objItem in colItems 
    VideoMemory = objItem.AdapterRAM/1024/1024 
Next 

'This returns various system information including current logged on user, 

domain, memory, manufacture and model. 
Set colItems = objWMIService.ExecQuery("Select * from 

Win32_ComputerSystem",,48) 
For Each objItem in colItems 
    UserName = objItem.UserName 
    Domain = objItem.Domain 
    TotalMemory = int((objItem.TotalPhysicalMemory/1024)/1024+1) 
    Manufacturer = objItem.Manufacturer 
    Model = objItem.Model 
    SysType = objItem.SystemType 
Next 

'This determines the total hard drive space and free hard drive space. 
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk 

Where Name='C:'",,48) 
For Each objItem in colItems 
    FreeHDSpace = Fix(((objItem.FreeSpace/1024)/1024)/1024) 
    TotalHDSpace = Fix(((objItem.Size/1024)/1024)/1024) 
Next 

'This section returns the default printer and printer port. 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer where 

Default=True", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) 
For Each objItem in colItems 
    Printer = objItem.Name 
    PortName = objItem.PortName 
Next 

'This returns the CPU information. 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", 

"WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) 
For Each objItem in colItems 
    CPUDesc = LTrim(objItem.Name) 
Next 


'// CPU Info 
For each objCPU in GetObject("winmgmts:{impersonationLevel=impersonate}\\" 

& strComputer & "\root\cimv2").InstancesOf("Win32_Processor") 
         Select Case objCPU.Family 
           Case 2 
             cputype = "Unknown" 
           Case 11 
             cputype = "Pentium brand" 
           Case 12 
             cputype = "Pentium Pro" 
           Case 13 
             cputype = "Pentium II" 
           Case 14 
             cputype = "Pentium processor with 

MMX technology" 
           Case 15 
             cputype = "Celeron " 
           Case 16 
             cputype = "Pentium II Xeon" 
           Case 17 
             cputype = "Pentium III" 
           Case 28 
             cputype = "AMD Athlon Processor 

Family" 
           Case 29 
             cputype = "AMD Duron Processor" 
           Case 30 
             cputype = "AMD2900 Family" 
           Case 31 
             cputype = "K6-2+" 
           Case 130 
             cputype = "Itanium Processor" 
           Case 176 
             cputype = "Pentium III Xeon" 
           Case 177 
             cputype = "Pentium III Processor 

with Intel SpeedStep Technology" 
           Case 178 
             cputype = "Pentium 4" 
           Case 179 
             cputype = "Intel Xeon" 
           Case 181 
             cputype = "Intel Xeon processor 

MP" 
           Case 182 
             cputype = "AMD AthlonXP Family" 
           Case 183 
             cputype = "AMD AthlonMP Family" 
           Case 184 
             cputype = "Intel Itanium 2" 
           Case 185 
             cputype = "AMD Opteron Family" 
       Case Else 
        cputype = "CPU Unidentified" 
         End Select 
Next 

'This returns the current uptime (time since last reboot) of the system. 
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from 

Win32_OperatingSystem") 
For Each objOS in colOperatingSystems 
    dtmBootup = objOS.LastBootUpTime 
    dtmLastBootupTime = WMIDateStringToDate(dtmBootup) 
    dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now) 
    Uptime = dtmSystemUptime 
Next 
Function WMIDateStringToDate(dtmBootup) 
    WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & Mid 

(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) & " " & Mid (dtmBootup, 9, 2) 

& ":" & Mid(dtmBootup, 11, 

2) & ":" & Mid(dtmBootup,13, 2)) 
End Function 

dim objFSO 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

' -- The heart of the create file script ----------------------- 
' -- Creates the file using the value of strFile on Line 11 
' -------------------------------------------------------------- 
Set fileOutput = objFSO.CreateTextFile("x.html", true) 

'Set fileOutput = objExplorer.Document 

'This is the code for the web page to be displayed. 

fileOutput.WriteLine "<html>" 
fileOutput.WriteLine " <head>" 
fileOutput.WriteLine "  <title>System Information for '" & WKID & "' 

</title>" 
fileOutput.WriteLine " </head>" 
fileOutput.WriteLine " <body bgcolor='#FFFFFF' text='#000000' 

link='#0000FF' vlink='000099' alink='#00FF00'>" 
fileOutput.WriteLine "  <center>" 
fileOutput.WriteLine "   <h1>System Information for " & WKID & 

"</h1>" 
fileOutput.WriteLine "   <table border='0' cellspacing='1' 

cellpadding='1' width='95%'>" 
fileOutput.WriteLine "    <tr><td background='" & ImgDir & 

"blue_spacer.gif'>" 
fileOutput.WriteLine "     <table border='0' 

cellspacing='0' cellpadding='0' width='100%'>" 
fileOutput.WriteLine "      <tr><td>" 
fileOutput.WriteLine "       <table border='0' 

cellspacing='0' cellpadding='0' width='100%'>" 
fileOutput.WriteLine "        <tr>" 
fileOutput.WriteLine "         <td width='5%' 

align='left' valign='middle' background='" & ImgDir & 

"blue_spacer.gif'><img src='" & ImgDir & 

"write.gif'></td>" 
fileOutput.WriteLine "         <td width='95%' 

align='left' valign='middle' background='" & ImgDir & "blue_spacer.gif'> 

<font 

color='#FFFFFF' size='5'>WKInfo - </font><font color='#FFFFFF' 

size='3'>General information on the Workstation.</font></td>" 
fileOutput.WriteLine "        </tr>" 
fileOutput.WriteLine "        <tr><td colspan='2' 

bgcolor='#FFFFFF'>" 
fileOutput.WriteLine "         <TABLE 

width='100%' cellspacing='0' cellpadding='2' border='1' 

bordercolor='#c0c0c0' 

bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
    fileOutput.WriteLine"             

<tr height=2><td height=10 align=center bgcolor=midnightblue 

colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Date and 

Time</h3></b></TD></TR>" 
    fileOutput.WriteLine"             

<tr height=2><td height=10 align=center bgcolor=midnightblue 

colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Date/Time</TD><td width='70%' 

bgcolor=#f0f0f0 

align=left><i>" & DateTime & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>System Uptime</TD><td 

width='70%' bgcolor=#f0f0f0 

align=left><i>" & Uptime & " hours</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Time Zone</TD><td width='70%' 

bgcolor=#f0f0f0 

align=left><i>" & Zone & " </i></td></tr>" 
    fileOutput.WriteLine"             

<tr height=2><td height=10 align=center bgcolor=midnightblue 

colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Computer 

Information</h3></b></TD></TR>" 
    fileOutput.WriteLine"             

<tr height=2><td height=10 align=center bgcolor=midnightblue 

colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Manufacturer</TD><td 

width='70%' bgcolor=#f0f0f0 

align=left><i>" & Manufacturer & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Model</TD><td width='70%' 

bgcolor=#f0f0f0 

align=left><i>" & Model & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>System Based</TD><td 

width='70%' bgcolor=#f0f0f0 

align=left><i>" & SysType & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Operating System</TD><td 

width='70%' bgcolor=#f0f0f0 

align=left><i>" & WKOS & " " & CSD & " " & Architecture & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Operating System Install 

Date</TD><td width='70%' 

bgcolor=#f0f0f0 align=left><i>" & InstallDate & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>UserName</TD><td width='70%' 

bgcolor=#f0f0f0 

align=left><i>" & UserName & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Workstation Name</TD><td 

width='70%' bgcolor=#f0f0f0 

align=left><i>" & WKID & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Domain</TD><td width='70%' 

bgcolor=#f0f0f0 

align=left><i>" & Domain & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>System Drive</TD><td 

width='70%' bgcolor=#f0f0f0 

align=left><i>" & SysDrive & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>System Directory</TD><td 

width='70%' bgcolor=#f0f0f0 

align=left><i>" & SysDir & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Windows Directory</TD><td 

width='70%' bgcolor=#f0f0f0 

align=left><i>" & WinDir & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Allocated 

Space</TD><td width='70%' 

bgcolor=#f0f0f0 align=left><i>" & Allocated & " MB</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Used 

Space</TD><td width='70%' 

bgcolor=#f0f0f0 align=left><i>" & UsedSpace & " MB</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Max Space</TD><td 

width='70%' 

bgcolor=#f0f0f0 align=left><i>" & MaxSpace & " MB</i></td></tr>" 
    fileOutput.WriteLine"             

<tr height=2><td height=10 align=center bgcolor=midnightblue 

colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Hardware 

Information</h3></b></TD></TR>" 
    fileOutput.WriteLine"             

<tr height=2><td height=10 align=center bgcolor=midnightblue 

colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>CPU</TD><td width='70%' 

bgcolor=#f0f0f0 

align=left><i>" & cputype & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Memory</TD><td width='70%' 

bgcolor=#f0f0f0 

align=left><i>" & TotalMemory & " MB</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Total HDD Space</TD><td 

width='70%' bgcolor=#f0f0f0 

align=left><i>" & TotalHDSpace & " GB</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Free HDD Space</TD><td 

width='70%' bgcolor=#f0f0f0 

align=left><i>" & FreeHDSpace & " GB</i></td></tr>" 
    fileOutput.WriteLine"             

<tr height=2><td height=10 align=center bgcolor=midnightblue 

colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Video Card 

Information</h3></b></TD></TR>" 
    fileOutput.WriteLine"             

<tr height=2><td height=10 align=center bgcolor=midnightblue 

colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Video Card</TD><td width='70%' 

bgcolor=#f0f0f0 

align=left><i>" & VideoCard & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Resolution</TD><td width='70%' 

bgcolor=#f0f0f0 

align=left><i>" & Resolution & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD 

width='30%' align='left' bgcolor='#e0e0e0'>Memory</TD><td width='70%' 

bgcolor=#f0f0f0 

align=left><i>" & VideoMemory & " MB</i></td></tr>" 
'This section lists all the current services and their status. 
fileOutput.WriteLine "          <TR><TD 

align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Current Service 

Information</h3></b></TD></TR>" 
fileOutput.WriteLine "          <tr><td 

colspan='2' bgcolor='#f0f0f0'>" 
fileOutput.WriteLine "           <TABLE 

width='100%' cellspacing='0' cellpadding='2' border='1' 

bordercolor='#c0c0c0' 

bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
fileOutput.WriteLine "             

<TR><TD width='70%' align='center' bgcolor='#e0e0e0'><b>Service 

Name</b></td><TD width='30%' 

align='center' bgcolor='#e0e0e0'><b>Service State</b></td><tr>" 
Set colRunningServices = objWMIService.ExecQuery("Select * from 

Win32_Service") 
For Each objService in colRunningServices 
fileOutput.WriteLine "           <TR><TD 

align='left' bgcolor='#f0f0f0'>" & objService.DisplayName & "</TD><td 

bgcolor=#f0f0f0 

align=center><i>" & objService.State & "</i></td></tr>" 
    wscript.echo "           <TR><TD 

align='left' bgcolor='#f0f0f0'>" & objService.DisplayName & "</TD><td 

bgcolor=#f0f0f0 

align=center><i>" & objService.State & "</i></td></tr>" 
Next 
fileOutput.WriteLine "            

</table>" 
fileOutput.WriteLine "          </td></tr>" 
'This section lists all the current running processes and some 

information. 
fileOutput.WriteLine "          <TR><TD 

align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Current Process 

Information</h3></b></TD></TR>" 
fileOutput.WriteLine "          <tr><td 

colspan='2' bgcolor='#f0f0f0'>" 
fileOutput.WriteLine "           <TABLE 

width='100%' cellspacing='0' cellpadding='2' border='1' 

bordercolor='#c0c0c0' 

bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
fileOutput.WriteLine "             

<TR><TD width='10%' align='center' bgcolor='#e0e0e0'><b>PID</b></td><TD 

width='35%' 

align='center' bgcolor='#e0e0e0'><b>Process Name</b></td><TD width='40%' 

align='center' bgcolor='#e0e0e0'><b>Owner</b></td><TD width='15%' 

align='center' 

bgcolor='#e0e0e0'><b>Memory</b></td></tr>" 
Set colProcessList = objWMIService.ExecQuery("Select * from 

Win32_Process") 
For Each objProcess in colProcessList 
colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain) 
fileOutput.WriteLine "             

<TR><TD align='center' bgcolor='#f0f0f0'>" & objProcess.Handle & "</td><TD 

align='center' 

bgcolor='#f0f0f0'>" & objProcess.Name & "</td><TD align='center' 

bgcolor='#f0f0f0'>" & strUserDomain & "\" & strNameOfUser & "</td><TD 

align='center' 

bgcolor='#f0f0f0'>" & objProcess.WorkingSetSize/1024 & " kb</td><tr>" 
Next 
fileOutput.WriteLine "            

</table>" 
fileOutput.WriteLine "          </td></tr>" 
'This section lists all the currently installed software on the machine. 
fileOutput.WriteLine "          <TR><TD 

align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Installed 

Software</i></b></TD></TR>" 
fileOutput.WriteLine "          <tr><td 

colspan='2' bgcolor='#f0f0f0'>" 
Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product") 
For Each objSoftware in colSoftware 
    fileOutput.WriteLine"            

<TABLE width='100%' cellspacing='0' cellpadding='2' border='1' 

bordercolor='#c0c0c0' 

bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
    fileOutput.WriteLine"             

<tr><td width=30% align=center bgcolor='#e0e0e0'><b>Name</b></td><td 

width=30% align=center 

bgcolor='#e0e0e0'><b>Vendor</b></td><td width=30% align=center 

bgcolor='#e0e0e0'><b>Version</b></td></tr>" 
    fileOutput.WriteLine"             

<tr><td align=center bgcolor=#f0f0f0>" & objSoftware.Name & "</td><td 

align=center 

bgcolor=#f0f0f0>" & objSoftware.Vendor & "</td><td align=center 

bgcolor=#f0f0f0>" & objSoftware.Version & "</td></tr>" 
    fileOutput.WriteLine"             

<tr height=2><td height=10 align=center bgcolor=midnightblue 

colspan=3></td></tr>" 
    fileOutput.WriteLine"            

</table>" 
Next 
fileOutput.WriteLine "          </td></tr>" 
fileOutput.WriteLine "         </table>" 
fileOutput.WriteLine "        </td></tr>" 
fileOutput.WriteLine "       </table>" 
fileOutput.WriteLine "      </td></tr>" 
fileOutput.WriteLine "     </table>" 
fileOutput.WriteLine "    </td></tr>" 
fileOutput.WriteLine "   </table>" 
fileOutput.WriteLine "   <p><small></small></p>" 
fileOutput.WriteLine "  </center>" 
fileOutput.WriteLine " </body>" 
fileOutput.WriteLine "<html>" 
fileOutput.close 
WScript.Quit 
0

Methical,

Je regardais votre script et avez mis à jour.

Il semblait y avoir un problème avec un tm (marque déposée) avec le script original. J'ai pris la liberté de mettre à jour le script pour travailler ..

Option Explicit 
Dim strComputer, objWMIService, propValue, objItem 
Dim strUserName, strPassword, colItems, SWBemlocator 
Dim ImgDir, DateTime, WKID, WKOS, CSD, Architecture, SysDir, SysDrive, WinDir, ServicePack, Zone 
Dim Allocated, UsedSpace, MaxSpace, objSWbemDateTime, colOperatingSystems, InstallDate, objOperatingSystem 
Dim VideoCard, Resolution, VideoMemory, UserName, Domain, TotalMemory, Manufacturer, Model, SysType 
Dim FreeHDSpace, TotalHDSpace, Printer, PortName, CPUDesc, cputype, objOS 
Dim dtmBootup, dtmLastBootupTime, dtmSystemUptime, Uptime, fileOutput 
Dim objService, colRunningServices, objProcess, colProcessList, objSoftware, colSoftware, strNameOfUser, strUserDomain 
Dim colProperties, PercentFree 

Const wbemFlagReturnImmediately = &h10 
Const wbemFlagForwardOnly = &h20 

' This section queries for the workstation to be scanned. 
strUserName = "" 
strPassword = "" 
strComputer = "127.0.0.1" 
ImgDir = "C:\Scripts\images\" 

'Sets up the connections and opjects to be used throughout the script. 
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator") 
Set objWMIService = SWBemlocator.ConnectServer(, "root\CIMV2", strUserName, strPassword) 

'This determines the current date and time of the PC being scanned. 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LocalTime", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) 
For Each objItem In colItems 
DateTime = objItem.Month & "/" & objItem.Day & "/" & objItem.Year & " - " & Right(100 + objItem.Hour, 2) & ":" & Right(100 + objItem.Minute, 2) & ":" & Right(100 + objItem.Second, 2) 
Next 

'Gets some ingomation about the Operating System including Service Pack level. 
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",, 48) 
For Each objItem In colItems 
WKID = objItem.CSName 
WKOS = objItem.Caption 
CSD = objItem.CSDVersion 
'Architecture = objItem.OSArchitecture 
SysDir = objItem.SystemDirectory 
SysDrive = objItem.SystemDrive 
WinDir = objItem.WindowsDirectory 
ServicePack = objItem.ServicePackMajorVersion & "." & objItem.ServicePackMinorVersion 
Next 

'This section returns the Time Zone 
Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone") 
For Each objItem In colItems 
Zone = objItem.Description 
Next 

'This section displays the Shadow Storage information 
'Set colItems = objWMIService.ExecQuery("Select * from Win32_ShadowStorage") 
'For Each objItem In colItems 
' Allocated = Int((objItem.AllocatedSpace/1024)/1024+1) 
' UsedSpace = Int((objItem.UsedSpace/1024)/1024+1) 
' MaxSpace = Int((objItem.MaxSpace/1024)/1024+1) 
'Next 

'This section returns the InstallDate of the OS 
Set objSWbemDateTime = _ 
CreateObject("WbemScripting.SWbemDateTime") 
Set colOperatingSystems = _ 
objWMIService.ExecQuery _ 
("Select * from Win32_OperatingSystem") 
For Each objOperatingSystem _ 
In colOperatingSystems 
objSWbemDateTime.Value = _ 
objOperatingSystem.InstallDate 
InstallDate = _ 
objSWbemDateTime.GetVarDate(False) 
Next 

'This section returns the Video card and current resolution. 
Set colItems = objWMIService.ExecQuery("Select * from Win32_DisplayConfiguration",, 48) 
For Each objItem In colItems 
VideoCard = objItem.DeviceName 
Resolution = objItem.PelsWidth & " x " & objItem.PelsHeight & " x " & objItem.BitsPerPel & " bits" 
Next 

'This section returns the Video card memory. 
Set objWMIService = GetObject("winmgmts:root\cimv2") 
Set colItems = objWMIService.ExecQuery("Select * from Win32_VideoController") 
For Each objItem In colItems 
VideoMemory = objItem.AdapterRAM/1024/1024 
Next 

'This returns various system information including current logged on user, domain, memory, manufacture and model. 
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",, 48) 
For Each objItem In colItems 
UserName = objItem.UserName 
Domain = objItem.Domain 
TotalMemory = Int((objItem.TotalPhysicalMemory/1024)/1024 + 1) 
Manufacturer = objItem.Manufacturer 
Model = objItem.Model 
SysType = objItem.SystemType 
Next 

'This determines the total hard drive space and free hard drive space. 
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where Name='C:'",, 48) 
For Each objItem In colItems 
FreeHDSpace = Fix(((objItem.FreeSpace/1024)/1024)/1024) 
TotalHDSpace = Fix(((objItem.Size/1024)/1024)/1024) 
Next 

'This section returns the default printer and printer port. 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer where Default=True", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) 
For Each objItem In colItems 
Printer = objItem.Name 
PortName = objItem.PortName 
Next 

'// CPU Info 
'This returns the CPU information. 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) 
For Each objItem In colItems 
CPUDesc = LTrim(objItem.Name) 
Select Case objItem.Family 
    Case 2 
    cputype = "Unknown" 
    Case 11 
    cputype = "Pentium brand" 
    Case 12 
    cputype = "Pentium Pro" 
    Case 13 
    cputype = "Pentium II" 
    Case 14 
    cputype = "Pentium processor with MMX technology" 
    Case 15 
    cputype = "Celeron " 
    Case 16 
    cputype = "Pentium II Xeon" 
    Case 17 
    cputype = "Pentium III" 
    Case 28 
    cputype = "AMD Athlon Processor Family" 
    Case 29 
    cputype = "AMD Duron Processor" 
    Case 30 
    cputype = "AMD2900 Family" 
    Case 31 
    cputype = "K6-2+" 
    Case 130 
    cputype = "Itanium Processor" 
    Case 176 
    cputype = "Pentium III Xeon" 
    Case 177 
    cputype = "Pentium III Processor with Intel SpeedStep Technology" 
    Case 178 
    cputype = "Pentium 4" 
    Case 179 
    cputype = "Intel Xeon" 
    Case 181 
    cputype = "Intel Xeon processor MP" 
    Case 182 
    cputype = "AMD AthlonXP Family" 
    Case 183 
    cputype = "AMD AthlonMP Family" 
    Case 184 
    cputype = "Intel Itanium 2" 
    Case 185 
    cputype = "AMD Opteron™ Family" 
    Case Else 
    cputype = "CPU Unidentified" 
End Select 
Next 

'This returns the current uptime (time since last reboot) of the system. 
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") 
For Each objOS In colOperatingSystems 
dtmBootup = objOS.LastBootUpTime 
dtmLastBootupTime = WMIDateStringToDate(dtmBootup) 
dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now) 
Uptime = dtmSystemUptime 
Next 
Function WMIDateStringToDate(dtmBootup) 
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) & " " & Mid(dtmBootup, 9, 2) & ":" & Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, 13, 2)) 
End Function 

Dim objFSO 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

' -- The heart of the create file script ----------------------- 
' -- Creates the file using the value of strFile on Line 11 
' -------------------------------------------------------------- 
Set fileOutput = objFSO.CreateTextFile("C:\Scripts\x.html", True) 

'Set fileOutput = objExplorer.Document 

'This is the code for the web page to be displayed. 

fileOutput.WriteLine "<html>" 
fileOutput.WriteLine " <head>" 
fileOutput.WriteLine "  <title>System Information for '" & WKID & "' </title>" 
fileOutput.WriteLine " </head>" 
fileOutput.WriteLine " <body bgcolor='#FFFFFF' text='#000000' link='#0000FF' vlink='000099' alink='#00FF00'>" 
fileOutput.WriteLine "  <center>" 
fileOutput.WriteLine "   <h1>System Information for " & WKID & "</h1>" 
fileOutput.WriteLine "   <table border='0' cellspacing='1' cellpadding='1' width='95%'>" 
fileOutput.WriteLine "    <tr><td background='" & ImgDir & "blue_spacer.gif'>" 
fileOutput.WriteLine "     <table border='0' cellspacing='0' cellpadding='0' width='100%'>" 
fileOutput.WriteLine "      <tr><td>" 
fileOutput.WriteLine "       <table border='0' cellspacing='0' cellpadding='0' width='100%'>" 
fileOutput.WriteLine "        <tr>" 
fileOutput.WriteLine "         <td width='5%' align='left' valign='middle' background='" & ImgDir & "blue_spacer.gif'><img src='" & ImgDir & "write.gif'></td>" 
fileOutput.WriteLine "         <td width='95%' align='left' valign='middle' background='" & ImgDir & "blue_spacer.gif'> <font color='#FFFFFF' size='5'>WKInfo - </font><font color='#FFFFFF' size='3'>General information on the Workstation.</font></td>" 
fileOutput.WriteLine "        </tr>" 
fileOutput.WriteLine "        <tr><td colspan='2' bgcolor='#FFFFFF'>" 
fileOutput.WriteLine "         <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
fileOutput.WriteLine "            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Date and Time</h3></b></TD></TR>" 
fileOutput.WriteLine "            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Date/Time</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & DateTime & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Uptime</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & Uptime & " hours</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Time Zone</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & Zone & " </i></td></tr>" 
fileOutput.WriteLine "            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Computer Information</h3></b></TD></TR>" 
fileOutput.WriteLine "            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Manufacturer</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & Manufacturer & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Model</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & Model & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Based</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & SysType & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Operating System</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & WKOS & " " & CSD & " " & Architecture & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Operating System Install Date</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & InstallDate & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>UserName</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & UserName & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Workstation Name</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & WKID & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Domain</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & Domain & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Drive</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & SysDrive & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Directory</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & SysDir & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Windows Directory</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & WinDir & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Allocated Space</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & Allocated & " MB</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Used Space</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & UsedSpace & " MB</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Max Space</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & MaxSpace & " MB</i></td></tr>" 
fileOutput.WriteLine "            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Hardware Information</h3></b></TD></TR>" 
fileOutput.WriteLine "            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>CPU</td><td width='70%' bgcolor=#f0f0f0 align = Left > <i>" & CPUDesc & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Memory</td><td width='70%' bgcolor=#f0f0f0 align = Left > <i>" & TotalMemory & " MB </i></td></tr>" 
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where DriveType = 3",, 48) 
For Each objItem In colItems 
FreeHDSpace = "" & objItem.Name & " Free Space: " & Fix(((objItem.FreeSpace/1024)/1024)/1024) 
TotalHDSpace = "" & objItem.Name & " Total Space: " & Fix(((objItem.Size/1024)/1024)/1024) 
PerCentFree = "" & objItem.Name & " Percent Free Space: " & 100 * FormatNumber(Fix(((objItem.FreeSpace/1024)/1024)/1024)/Fix(((objItem.Size/1024)/1024)/1024), 2) 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Total HDD Space</td><td width='70%' bgcolor=#f0f0f0 align = Left > <i>" & TotalHDSpace & " GB </i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Free HDD Space</td><td width='70%' bgcolor=#f0f0f0 align = Left > <i>" & FreeHDSpace & " GB </i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Percent Free HDD Space</td><td width='70%' bgcolor=#f0f0f0 align = Left > <i>" & PerCentFree & "%</i></td></tr>" 
Next 
fileOutput.WriteLine "            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Video Card Information</h3></b></TD></TR>" 
fileOutput.WriteLine "            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Video Card</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & VideoCard & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Video Resolution</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & Resolution & "</i></td></tr>" 
fileOutput.WriteLine "          <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Video Memory</TD><td width='70%' bgcolor=#f0f0f0 align=Left><i>" & VideoMemory & " MB</i></td></tr>" 
'This section lists all the current services and their status. 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Current Service Information</h3></b></TD></TR>" 
fileOutput.WriteLine "          <tr><td colspan='2' bgcolor='#f0f0f0'>" 
fileOutput.WriteLine "           <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
fileOutput.WriteLine "            <TR><TD width='70%' align='center' bgcolor='#e0e0e0'><b>Service Name</b></td><TD width='30%' align='center' bgcolor='#e0e0e0'><b>Service State</b></td><tr>" 
Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service") 
For Each objService In colRunningServices 
fileOutput.WriteLine "           <TR><TD align='left' bgcolor='#f0f0f0'>" & objService.DisplayName & "</TD><td bgcolor=#f0f0f0 align=center><i>" & objService.State & "</i></td></tr>" 
'WScript.echo "           <TR><TD align='left' bgcolor='#f0f0f0'>" & objService.DisplayName & "</TD><td bgcolor=#f0f0f0 align=center><i>" & objService.State & "</i></td></tr>" 
Next 
fileOutput.WriteLine "            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "           </table>" 
fileOutput.WriteLine "          </td></tr>" 
'This section lists all the current running processes and some information. 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Current Process Information</h3></b></TD></TR>" 
fileOutput.WriteLine "          <tr><td colspan='2' bgcolor='#f0f0f0'>" 
fileOutput.WriteLine "           <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
fileOutput.WriteLine "            <TR><TD width='10%' align='center' bgcolor='#e0e0e0'><b>PID</b></td><TD width='35%' align='center' bgcolor='#e0e0e0'><b>Process Name</b></td><TD width='40%' align='center' bgcolor='#e0e0e0'><b>Process Owner</b></td><TD width='15%' align='center' bgcolor='#e0e0e0'><b>Memory Used</b></td></tr>" 
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process") 
For Each objProcess In colProcessList 
colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain) 
fileOutput.WriteLine "            <TR><TD align='center' bgcolor='#f0f0f0'>" & objProcess.Handle & "</td><TD align='center' bgcolor='#f0f0f0'>" & objProcess.Name & "</td><TD align='center' bgcolor='#f0f0f0'>" & strUserDomain & "\" & strNameOfUser & "</td><TD align='center' bgcolor='#f0f0f0'>" & objProcess.WorkingSetSize/1024 & " kb</td><tr>" 
'fileOutput.WriteLine "            <TR><TD align='center' bgcolor='#f0f0f0'>" & objProcess.Handle & "</td><TD align='center' bgcolor='#f0f0f0'>" & objProcess.Name & "</td><TD align='center' bgcolor='#f0f0f0'></td><TD align='center' bgcolor='#f0f0f0'>" & objProcess.WorkingSetSize/1024 & " kb</td><tr>" 
Next 
fileOutput.WriteLine "            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=4></td></tr>" 
fileOutput.WriteLine "           </table>" 
fileOutput.WriteLine "          </td></tr>" 
'This section lists all the currently installed software on the machine. 
fileOutput.WriteLine "          <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Installed Software</i></b></TD></TR>" 
fileOutput.WriteLine "          <tr><td colspan='2' bgcolor='#f0f0f0'>" 
fileOutput.WriteLine "           <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>" 
fileOutput.WriteLine "            <tr><td width=30% align=center bgcolor='#e0e0e0'><b>Name</b></td><td width=30% align=center bgcolor='#e0e0e0'><b>Vendor</b></td><td width=30% align=center bgcolor='#e0e0e0'><b>Version</b></td></tr>" 
Set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product") 
For Each objSoftware In colSoftware 
fileOutput.WriteLine "            <tr><td align=center bgcolor=#f0f0f0>" & objSoftware.Name & "</td><td align=center bgcolor=#f0f0f0>" & objSoftware.Vendor & "</td><td align=center bgcolor=#f0f0f0>" & objSoftware.Version & "</td></tr>" 
Next 
fileOutput.WriteLine "            <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>" 
fileOutput.WriteLine "           </table>" 
fileOutput.WriteLine "          </td></tr>" 
fileOutput.WriteLine "         </table>" 
fileOutput.WriteLine "        </td></tr>" 
fileOutput.WriteLine "       </table>" 
fileOutput.WriteLine "      </td></tr>" 
fileOutput.WriteLine "     </table>" 
fileOutput.WriteLine "    </td></tr>" 
fileOutput.WriteLine "   </table>" 
fileOutput.WriteLine "   <p><small></small></p>" 
fileOutput.WriteLine "  </center>" 
fileOutput.WriteLine " </body>" 
fileOutput.WriteLine "<html>" 
fileOutput.close 
WScript.Quit 
Questions connexes