How to create text file and write to it in vbscript

后端 未结 3 1497
长发绾君心
长发绾君心 2020-12-02 02:40

I have the following script which locates all access files on a machine:

strComputer = \".\"

Set objWMIService = GetObject(\"winmgmts:\\\\\" & strComput         


        
3条回答
  •  甜味超标
    2020-12-02 02:45

    Simple Google search like "vbscript create and write to text file" will give you ocean of information on how to tackle this. Anyway here is simplest one to give you kick start.

    '~ Create a FileSystemObject
    Set objFSO=CreateObject("Scripting.FileSystemObject")
    
    '~ Provide file path
    outFile="YouFolderPath\Results.txt"
    
    '~ Setting up file to write
    Set objFile = objFSO.CreateTextFile(outFile,True)
    
    
    strComputer = "."
    
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    
    Set colFiles = objWMIService.ExecQuery _
        ("Select * from CIM_DataFile Where Extension = 'mdb' OR Extension = 'ldb'")
    
    For Each obj_File in colFiles
        'Wscript.Echo objFile.Name  'Commented out
    
        '~ Write to file
        objFile.WriteLine obj_File.Name
    Next
    
    '~ Close the file
    objFile.Close
    

提交回复
热议问题