VBS 计算机信息脚本
有人可以帮我修改这个吗?
不是在开始时出现询问计算机 ID/名称的对话框,而是有没有自动输入的对话框,所以它都是自动的? 最后,不打开文件,只是将其存储在硬盘上(与脚本相同的目录)
On Error Resume Next
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, objWMIService, propValue, objItem
Dim strUserName, strPassword, colItems, SWBemlocator
' This section queries for the workstation to be scanned.
strComputer = inputbox ("Workstation", "Enter the workstation ID to scan.",".")
UserName = ""
Password = ""
ImgDir = "C:\Scripts\images\"
'Sets up the connections and objects to be used throughout the script.
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"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 information 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
ServicePack = objItem.ServicePackMajorVersion & "." & objItem.ServicePackMinorVersion
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:\\" & strComputer & "\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
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
'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
'This sets up the Internet Explorer window in order to show the results.
Set objExplorer = WScript.CreateObject("InternetExplorer.Application", "IE_")
With objExplorer
.Navigate "about:Blank"
.Toolbar = 0
.StatusBar = 0
.Width = 800
.Height = 600
.Left = 75
.Top = 0
.Visible = 1
End With
Set fileOutput = objExplorer.Document
'This is the code for the web page to be displayed.
fileOutput.Open
fileOutput.WriteLn "<html>"
fileOutput.WriteLn " <head>"
fileOutput.WriteLn " <title>System Information for '" & WKID & "' </title>"
fileOutput.WriteLn " </head>"
fileOutput.WriteLn " <body bgcolor='#FFFFFF' text='#000000' link='#0000FF' vlink='000099' alink='#00FF00'>"
fileOutput.WriteLn " <center>"
fileOutput.WriteLn " <h3>Workstaion/Server Information for " & WKID & "</h3>"
fileOutput.WriteLn " <table border='0' cellspacing='1' cellpadding='1' width='95%'>"
fileOutput.WriteLn " <tr><td background='" & ImgDir & "blue_spacer.gif'>"
fileOutput.WriteLn " <table border='0' cellspacing='0' cellpadding='0' width='100%'>"
fileOutput.WriteLn " <tr><td>"
fileOutput.WriteLn " <table border='0' cellspacing='0' cellpadding='0' width='100%'>"
fileOutput.WriteLn " <tr>"
fileOutput.WriteLn " <td width='5%' align='left' valign='middle' background='" & ImgDir & "blue_spacer.gif'><img src='" & ImgDir & "write.gif'></td>"
fileOutput.WriteLn " <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.WriteLn " </tr>"
fileOutput.WriteLn " <tr><td colspan='2' bgcolor='#FFFFFF'>"
fileOutput.WriteLn " <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Last Scanned</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Date/Time</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & DateTime & "</i></td></tr>"
fileOutput.WriteLn " <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.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>General Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Workstation ID</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & WKID & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Domain</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & Domain & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>UserName</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & UserName & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>General OS Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Operating System</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & WKOS & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Service Pack</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & ServicePack & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>General Computer Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Manufacturer</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & Manufacturer & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Model</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & Model & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>General Hardware Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>CPU</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & CPUDesc & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Memory</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & TotalMemory & " MB</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Total HD Space</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & TotalHDSpace & " GB</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Free HD Space</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & FreeHDSpace & " GB</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>General Video Card Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Video Card</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & VideoCard & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Resolution</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & Resolution & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Memory</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & VideoMemory & " MB</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Default Printer Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Printer</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & Printer & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Port Name</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & PortName & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Shared Directories</i></b></TD></TR>"
'This sextion lists all the current shares enabled on the PC.
fileOutput.WriteLn " <tr><td colspan='2' bgcolor='#f0f0f0'>"
fileOutput.WriteLn " <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLn " <TR><TD width='30%' align='center' bgcolor='#e0e0e0'><b>Name</b></td><TD width='40%' align='center' bgcolor='#e0e0e0'><b>Path</b><TD width='40%' align='center' bgcolor='#e0e0e0'><b>Description</b></td><tr>"
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
For each objShare in colShares
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#f0f0f0'><i>" & objShare.Name & "</i></TD><td bgcolor=#f0f0f0 align=left><i>" & objShare.Path & "</i></TD><td bgcolor=#f0f0f0 align=left><i>" & objShare.Caption & "</i></td></tr>"
Next
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
'This section lists all the current services and their status.
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Current Service Information</i></b></TD></TR>"
fileOutput.WriteLn " <tr><td colspan='2' bgcolor='#f0f0f0'>"
fileOutput.WriteLn " <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLn " <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.WriteLn " <TR><TD align='left' bgcolor='#f0f0f0'>" & objService.DisplayName & "</TD><td bgcolor=#f0f0f0 align=center><i>" & objService.State & "</i></td></tr>"
Next
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
'This section lists all the current running processes and some information.
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Current Process Information</i></b></TD></TR>"
fileOutput.WriteLn " <tr><td colspan='2' bgcolor='#f0f0f0'>"
fileOutput.WriteLn " <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLn " <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.WriteLn " <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.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
'This section lists all the currently installed software on the machine.
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Installed Software</i></b></TD></TR>"
fileOutput.WriteLn " <tr><td colspan='2' bgcolor='#f0f0f0'>"
Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product")
For Each objSoftware in colSoftware
fileOutput.WriteLn" <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLn" <tr><td align=left bgcolor='#e0e0e0'><b>Caption:</b></td><td colspan=2 bgcolor=#f0f0f0>" & objSoftware.Caption & "</td></tr>"
fileOutput.WriteLn" <tr><td align=left bgcolor='#e0e0e0'><b>Install Location:</b></td><td colspan=2 bgcolor=#f0f0f0>" & objSoftware.InstallLocation & "</td></tr>"
fileOutput.WriteLn" <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.WriteLn" <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.WriteLn" <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>"
fileOutput.WriteLn" </table>"
Next
fileOutput.WriteLn " </td></tr>"
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " <p><small></small></p>"
fileOutput.WriteLn " </center>"
fileOutput.WriteLn " </body>"
fileOutput.WriteLn "<html>"
fileOutput.close
WScript.Quit
Can someone help me modify this please?
Instead of the dialog box appearing at the start to ask for computer ID/Name, is there anyway for this to be automatically put in, so its all automatic? And at the end, not to open the file, just to have it stored on the hdd (same dir as script)
On Error Resume Next
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, objWMIService, propValue, objItem
Dim strUserName, strPassword, colItems, SWBemlocator
' This section queries for the workstation to be scanned.
strComputer = inputbox ("Workstation", "Enter the workstation ID to scan.",".")
UserName = ""
Password = ""
ImgDir = "C:\Scripts\images\"
'Sets up the connections and objects to be used throughout the script.
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"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 information 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
ServicePack = objItem.ServicePackMajorVersion & "." & objItem.ServicePackMinorVersion
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:\\" & strComputer & "\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
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
'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
'This sets up the Internet Explorer window in order to show the results.
Set objExplorer = WScript.CreateObject("InternetExplorer.Application", "IE_")
With objExplorer
.Navigate "about:Blank"
.Toolbar = 0
.StatusBar = 0
.Width = 800
.Height = 600
.Left = 75
.Top = 0
.Visible = 1
End With
Set fileOutput = objExplorer.Document
'This is the code for the web page to be displayed.
fileOutput.Open
fileOutput.WriteLn "<html>"
fileOutput.WriteLn " <head>"
fileOutput.WriteLn " <title>System Information for '" & WKID & "' </title>"
fileOutput.WriteLn " </head>"
fileOutput.WriteLn " <body bgcolor='#FFFFFF' text='#000000' link='#0000FF' vlink='000099' alink='#00FF00'>"
fileOutput.WriteLn " <center>"
fileOutput.WriteLn " <h3>Workstaion/Server Information for " & WKID & "</h3>"
fileOutput.WriteLn " <table border='0' cellspacing='1' cellpadding='1' width='95%'>"
fileOutput.WriteLn " <tr><td background='" & ImgDir & "blue_spacer.gif'>"
fileOutput.WriteLn " <table border='0' cellspacing='0' cellpadding='0' width='100%'>"
fileOutput.WriteLn " <tr><td>"
fileOutput.WriteLn " <table border='0' cellspacing='0' cellpadding='0' width='100%'>"
fileOutput.WriteLn " <tr>"
fileOutput.WriteLn " <td width='5%' align='left' valign='middle' background='" & ImgDir & "blue_spacer.gif'><img src='" & ImgDir & "write.gif'></td>"
fileOutput.WriteLn " <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.WriteLn " </tr>"
fileOutput.WriteLn " <tr><td colspan='2' bgcolor='#FFFFFF'>"
fileOutput.WriteLn " <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Last Scanned</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Date/Time</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & DateTime & "</i></td></tr>"
fileOutput.WriteLn " <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.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>General Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Workstation ID</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & WKID & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Domain</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & Domain & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>UserName</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & UserName & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>General OS Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Operating System</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & WKOS & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Service Pack</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & ServicePack & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>General Computer Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Manufacturer</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & Manufacturer & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Model</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & Model & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>General Hardware Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>CPU</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & CPUDesc & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Memory</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & TotalMemory & " MB</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Total HD Space</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & TotalHDSpace & " GB</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Free HD Space</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & FreeHDSpace & " GB</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>General Video Card Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Video Card</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & VideoCard & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Resolution</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & Resolution & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Memory</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & VideoMemory & " MB</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Default Printer Information</i></b></TD></TR>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Printer</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & Printer & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Port Name</TD><td width='70%' bgcolor=#f0f0f0 align=left><i>" & PortName & "</i></td></tr>"
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Shared Directories</i></b></TD></TR>"
'This sextion lists all the current shares enabled on the PC.
fileOutput.WriteLn " <tr><td colspan='2' bgcolor='#f0f0f0'>"
fileOutput.WriteLn " <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLn " <TR><TD width='30%' align='center' bgcolor='#e0e0e0'><b>Name</b></td><TD width='40%' align='center' bgcolor='#e0e0e0'><b>Path</b><TD width='40%' align='center' bgcolor='#e0e0e0'><b>Description</b></td><tr>"
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
For each objShare in colShares
fileOutput.WriteLn " <TR><TD width='30%' align='left' bgcolor='#f0f0f0'><i>" & objShare.Name & "</i></TD><td bgcolor=#f0f0f0 align=left><i>" & objShare.Path & "</i></TD><td bgcolor=#f0f0f0 align=left><i>" & objShare.Caption & "</i></td></tr>"
Next
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
'This section lists all the current services and their status.
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Current Service Information</i></b></TD></TR>"
fileOutput.WriteLn " <tr><td colspan='2' bgcolor='#f0f0f0'>"
fileOutput.WriteLn " <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLn " <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.WriteLn " <TR><TD align='left' bgcolor='#f0f0f0'>" & objService.DisplayName & "</TD><td bgcolor=#f0f0f0 align=center><i>" & objService.State & "</i></td></tr>"
Next
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
'This section lists all the current running processes and some information.
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Current Process Information</i></b></TD></TR>"
fileOutput.WriteLn " <tr><td colspan='2' bgcolor='#f0f0f0'>"
fileOutput.WriteLn " <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLn " <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.WriteLn " <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.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
'This section lists all the currently installed software on the machine.
fileOutput.WriteLn " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Installed Software</i></b></TD></TR>"
fileOutput.WriteLn " <tr><td colspan='2' bgcolor='#f0f0f0'>"
Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product")
For Each objSoftware in colSoftware
fileOutput.WriteLn" <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0' bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLn" <tr><td align=left bgcolor='#e0e0e0'><b>Caption:</b></td><td colspan=2 bgcolor=#f0f0f0>" & objSoftware.Caption & "</td></tr>"
fileOutput.WriteLn" <tr><td align=left bgcolor='#e0e0e0'><b>Install Location:</b></td><td colspan=2 bgcolor=#f0f0f0>" & objSoftware.InstallLocation & "</td></tr>"
fileOutput.WriteLn" <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.WriteLn" <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.WriteLn" <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>"
fileOutput.WriteLn" </table>"
Next
fileOutput.WriteLn " </td></tr>"
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " </td></tr>"
fileOutput.WriteLn " </table>"
fileOutput.WriteLn " <p><small></small></p>"
fileOutput.WriteLn " </center>"
fileOutput.WriteLn " </body>"
fileOutput.WriteLn "<html>"
fileOutput.close
WScript.Quit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是您的代码的稍作修改的版本。 它采用要查询的工作站名称作为命令行参数,以及两个可选参数:用户名和密码。 我没有将结果输出到 IE 窗口,而是进行了轻微的更改,以使用文件系统对象将 html 代码输出到名为:workstation.html 的文件,其中工作站是传递给脚本时扫描的实际工作站名称。
我添加的代码部分位于两个位置,即顶部和 IE 窗口部分之前,我在两个位置都放置了 ' ************* 注释,以便您可以快速找到它们。 我保留了您的 fileoutput var,但将其从 fileOutput.writeln 修改为 fileOutput.writeline。
有关 FileSystemObject 的更多详细信息,请查看 MSDN此处文章。
有关 cscript.exe 的命令行选项请查看这篇 MSDN 文章。
这是一个 MS TechNet 页面,其中包含有关 在 VBS 中使用命令行参数。
Here is a slightly modified version of your code. It takes as command line arguments the workstation name to query, as well as two optional parameters, username and password. Instead of outputting the results to an IE window, I made a slight change to use the File System object to output your html code to a file called: workstation.html, where workstation is the actual workstation name that was scanned as passed to the script.
The sections of code I added are in two locations, at the top and right before the IE window portion, I have put ' ************* comments around both so you can spot them quickly. I left your fileoutput var but modified it from fileOutput.writeln to fileOutput.writeline.
For more detail on the FileSystemObject check out the MSDN article here.
For detail on command line options with cscript.exe check out this MSDN article.
Here is a MS TechNet page with good information on using command line arguments in VBS.
这是一个修改后的副本,显示了在计算机名中“硬编码”或仅使用本地计算机(通过“.”、“127.0.0.1”或“PCNAME”)的三种不同方法。
它还将保存结果“MyFile.log”。
Here's a modified copy that shows three different ways to "hard-code" in the computername, or just use the local computer (by ".", "127.0.0.1", or "PCNAME").
It will also save out a "MyFile.log" with the results.
如果您查看
SWbemLocator.ConnectServer Method,
您将看到计算机name 是可选的,因此只需使用 , 从运行脚本的计算机获取详细信息。
ie:
那么不要打开ie文档,只是打开并写入文件,使用writeLine而不是writeLn。
还要更改此行:
设置
objWMIService = GetObject("winmgmts:root\cimv2")
if you look at
SWbemLocator.ConnectServer Method
you will see that the computer name is optional so just use , to get the details from the computer running the script.
ie:
Then don't open an ie document, just open and write to a file, using writeLine instead of writeLn.
Also change this line:
to
Set objWMIService = GetObject("winmgmts:root\cimv2")
嘿,我实际上一开始就摆脱了登录框,只是在这里删除了这些行。
现在如果我知道如何修改它,以便它将 html 保存到硬盘驱动器,而不是仅仅打开它。 我不是 VB 脚本编写者,我只编写 HTML 哈哈
Heh, I actually got rid of the login box at the start just be removing these lines here..
Now if only i knew how to modify it so it saves the html to the hard drive instead of just opening it. I'm not a VB scripter, I do HTML only lol
这是一个完整的文件,它写入当前文件夹中的 x.html:
Here is a completed file, it writes to x.html in the current folder: