查找计算机模型并存储在文本文件中

时间:2014-09-09 18:31:13

标签: vbscript

我需要一些帮助。此脚本用于查找计算机模型并将其放入 文本文件。它似乎没有起作用。没有任何错误或任何错误,所以我有点卡住了。任何帮助都会很棒,因为我是VBScript的新手。

Class classname

    dim objFSO  
    dim objFOLDER 
    dim objFile 
    dim strDir 
    dim strFile 

    Sub subname1()
        strComputer = "." 
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
        Set colItems = objWMIService.ExecQuery( _
            "SELECT * FROM Win32_ComputerSystem",,48) 

        'For loop to cycle through each result
        For Each objItem in colItems
            'Calling the other sub ***just an example*** place where needed.
            Subname2()
            objModel = objItem.Model
            'enable only when trying to obtain exact model number
            Wscript.Echo objModel
        next
    End Sub

    'New Sub that will be called by first sub
     Sub Subname2()
        Explicit
        strDir = "c:\model"
        strFile = objModel
        set objFSO = CreateObject("Scripting.FileSystemObject")
        set objFOLDER = objFSO.CreateFolder(strDir)
        set objFile = objFSO.CreateTextFile(strDir & strFile)

        Wscript.Quit
    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

你还没有真正说出你想要放在你创建的文件中的内容,但你实际上并没有将任何内容传递给subname2,并且有很多不必要的变量作用于该类,这是相当的混乱。这应创建一个以c:\model中的PC模型命名的文本文件,前提是该模型中没有任何无效字符:

Class classname


    Sub subname1()
        dim wmi
        dim colItems
        dim objItem

        Set wmi = GetObject("winmgmts:\\.\root\CIMV2") 
        Set colItems = wmi.ExecQuery( _
            "SELECT * FROM Win32_ComputerSystem",,48) 

        'For loop to cycle through each result
        For Each objItem in colItems
            'Calling the other sub ***just an example*** place where needed.
            Subname2(objItem.Model)
        next
    End Sub

    'New Sub that will be called by first sub
     Sub Subname2(model)
        dim fso
        dim ofile

        set fso = CreateObject("Scripting.FileSystemObject")
        fso.CreateFolder("c:\model\")
        set ofile = fso.CreateTextFile("c:\model\" & model & ".txt")
        ofile.close
        Wscript.Quit
    End Sub
End Class

这是你的意思吗?