none
VBS脚本错误,可以帮忙看看吧? RRS feed

  • 问题

  •  VBS脚本错误,可以帮忙看看吧?虽说是脚本语言,但是和VB差不多,对吧。

    [code]

    '==========================================================================
    '
    ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
    ' NAME:
    ' COMMENT:
    '
    '==========================================================================
    'on error resume next
    Set wshshell=Wscript.Createobject("Wscript.shell")
    Wshshell.Run ("%comspec% /c regsvr32 /s scrrun.dll"),0,True
    Wshshell.Run ("%comspec% /c sc config  winmgmt start= auto"),0,True
    Wshshell.Run ("%comspec% /c net start winmgmt"),0
    'Set WshNetwork = WScript.Createobject("WScript.Network")
    'computername=WshNetwork.ComputerName

    strComputer = InputBox("请输入要查询的计算机名称",,"")
    Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
    Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, "root\cimv2")
    'SWbemServices.Security_.ImpersonationLeobjvel = 3

    set Fso=createobject("scripting.filesystemobject")
    ResoultFilePath= strComputer &".html"
    set ResultFilee= Fso.Createtextfile(ResoultFilePath)

    ResultFilee.Writeline "<html>"
    ResultFilee.writeline "<head>"
    ResultFilee.writeline "<title>硬件配置清单</title>"
    ResultFilee.writeline "</head>"

    ResultFilee.writeline "<body>"
    ResultFilee.writeline "<h3>" & strComputer & "硬件配置报告 -- Date:"&Now()&" </h3>" & VbCrLf

    ResultFilee.writeline "<table width=""90%"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""1""

    bgcolor=""#0000FF"">"
    ResultFilee.writeline "<tr>"
    ResultFilee.writeline "<th width=""30%"" height=""25"" bgcolor=""#FFFFFF"" scope=""col"">资产类型</th>"
    ResultFilee.writeline "<th bgcolor=""#FFFFFF"" scope=""col"">查询结果值</th>"
    ResultFilee.writeline "</tr>"
    Strstyle = "<th width=""30%"" height=""25"" bgcolor=""#FFFFFF"" scope=""row"">"

    OSopt()
    '----------WriteOS
    Function OSopt()
    set OS =objSWbemServices.execQuery("select * from win32_OperatingSystem",,48)
    for each item in OS
    OSVer = (Trim(item.Caption & item.Version))
    wscript.echo OSver
    WriteBG "操作系统",OSVer
    Next
    End Function

    Boardopt()
    '-----------MotherBoard
    Function Boardopt()
    set board = objSWbemServices.execQuery("select * from win32_baseboard")
    for each item in board
    boardName = (Trim(item.Product))
    WriteBG "主板",boardName
    Next
    End Function

    Cpuopt()
    '-----------CPU
    function Cpuopt()
    Set cpu =objSWbemServices.execQuery("select * from win32_processor")
    for each item in cpu
    cpuName =  (Trim(item.Name))
    WriteBG "中央处理器",cpuName
    Next
    End Function


    Memoryopt()
    '----------Memory
    Function Memoryopt()
    MTotal = 0
    Num = 0
    Mill = 0
    Set colItems = objSWbemServices.ExecQuery("Select * from Win32_PhysicalMemory",,48)
    For Each objItem in colItems
    Mill = objitem.capacity/1048576
    WriteBG "单根内存容量",Mill & "M"
    MTotal = MTotal+Mill
    Num = Num + 1
    Next
    WriteBG "总计内存",Num & "条" & "一共" & MTotal & "M"
    End Function

    Harddiskopt()
    '----------HardDisk
    Function Harddiskopt()
    Set colItems = objSWbemServices.ExecQuery("Select * from Win32_DiskDrive", , 48)
        For Each objItem In colItems
        diskName= (Trim(objItem.Caption))
        diskSize= (Trim(fix(objItem.size/1073741824)))
        WriteBG "硬盘",diskName & " 容量:" & diskSize & "G"
        Next
    End Function

    Videoopt()
    '----------Video
    Function videoopt()
    Set colItems = objSWbemServices.ExecQuery("Select * from Win32_VideoController", , 48)
        For Each objItem In colItems
        videoName = (Trim(objItem.Caption) & (objItem.VideoModeDescription))
        WriteBG "显示卡",videoName
    Next
    End Function

    Netcardopt()
    Function Netcardopt()
    '----------Netcard
    Set colItems = objSWbemServices.ExecQuery("Select * from Win32_NetworkAdapter where PhysicalAdapter=TRUE", , 48)
        For Each objItem In colItems
     NCname =  (Trim(objItem.ProductName))
     WriteBG "网卡",NCname
     NCmac =  (Trim(objItem.MACAddress))
     WriteBG "网卡MAC",NCmac
     Next
    End Function

    ResultFilee.writeline "</table>"
    ResultFilee.writeline "</body>"
    ResultFilee.writeline "</html>"
    ResultFilee.close
    wscript.echo "查询完成!"


    Function WriteBG(caption,value)
    ResultFilee.writeline "<tr>"
    ResultFilee.writeline "<td align=""Left"" width=""30%"" height=""25"" bgcolor=""#FFFFFF""

    scope=""row"">&nbsp;&nbsp;" & caption & "</td>"
    ResultFilee.writeline "<td bgcolor=""#FFFFFF"">&nbsp;&nbsp;" & value & "</td>"
    ResultFilee.writeline "</tr>"
    End Function

    [/code]

    该脚本有以下异常。
    1、连接的计算机是Vsita话,版本号是带有"©”,“™“,这种符号,脚本会直接报错,参数错误
    2、连接的计算机是2003,XP的话,无法获得物理网卡,提示“PhysicalAdapter”不可用。
    3、如果连接对象是XP,则报“RPC服务不可用”的错误。


    GOo。.
    2009年2月25日 8:58

答案

全部回复