佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 590|回复: 7

VBScript Export去Excel后分开cells的问题

[复制链接]
发表于 13-1-2017 12:44 PM | 显示全部楼层 |阅读模式
大家好,小弟是个vbscript白痴。
我在网上找到了一个vbscript,能够把电脑里所安装的软件全部export去excel里。
可是export后全部都是在同一个column,有谁能够教我改这个script怎样把它分开啊?
比如Computer Name是column A,Application是column B,Vendor是column C,Version是column D。
谢谢各位高手。

'*******************************************************************************
' software.vbs
' Create a list of software installed on one or more
' machines in TSV format.
'
' Usage: cscript.exe software.vbs [/path:<path>] [machine names]
'
' If <path> is given, the script will attempt to store logs
' in that location. It is treated as a relative path and must
' end in a backslash.
'*******************************************************************************

' Define a bunch of constants VBScript should define for us but doesn't
Const ForReading = 1, ForWriting = 2, ForAppending = 8

' Get shell and network
Set objShell = CreateObject("Wscript.Shell"
Set objNet = CreateObject("WScript.Network"
Set objArgs = WScript.Arguments

' Array to hold computer names
Dim arrComputers()

' Get attributes, if we got command line arguments, use those
' as the hostnames. Otherwise use the local machine name.
If objArgs.Unnamed.Length > 0 Then
    Dim i
    i = 0
    While i < objArgs.Unnamed.Length
        ReDim Preserve arrComputers(i)
        arrComputers(i) = objArgs.Unnamed.Item(i)
        i = i + 1
    Wend
Else
    ReDim arrComputers(0)
    arrComputers(0) = objNet.ComputerName
End If

' Get named arguments if they were passed
Dim strLogPath

If objArgs.Named.Length > 0 Then
    strLogPath = objArgs.Named.Item("path"
Else
    strLogPath = ""
End If

' Create a FSO to write the output to a text file
Set objFSO = CreateObject("Scripting.FileSystemObject"

' Get a list of software from each machine and format it as TSV.
For Each strComputer In arrComputers
    ' Put some error handling in here, if we can't contact the computer
    ' then we log the failure and move on.
    On Error Resume Next
    ' Get the list of installed software
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2"
    Set colItems = objWMIService.ExecQuery("Select * FROM Win32_Product",,48)
   
    If Err.Number <> 0 Then
        ' An error occurred trying to contact the machine, skip this computer
        ' and log the error so it can be noted and investigated.
        objShell.LogEvent 1, "software.vbs: Could not contact computer: " & _
            strComputer
        On Error Goto 0
    Else
        ' No error contacting the machine so write the log file.
        On Error Goto 0
        ' Create and/or open the log file
        Dim currentDate
        currentDate = Date
        Dim currentTime
        currentTime = Time
        Set objLogFile = objFSO.OpenTextFile(_
            strLogPath & _
            strComputer & _
            "_" & _
            Year(currentDate) & _
            "-" & _
            Month(currentDate) & _
            "-" & _
            Day(currentDate) & _
            "-" & _
            Hour(currentTime) & _
            "-" & _
            Minute(currentTime) & _
            "-" & _
            Second(currentTime) & _
            "_" & _
            "log.csv", ForWriting, True)

        ' Start the tsv
        objLogFile.WriteLine _
            "computer" & _
            vbTab & _
            "application" & _
            vbTab & _
            "vendor" & _
            vbTab & _
            "version"
        
        ' Build the tsv
        For Each objItem In colItems
            objLogFile.WriteLine _
                strComputer & vbTab & _
                objItem.Name & vbTab & _
                objItem.Vendor & vbTab & _
                objItem.Version
        Next
        
        ' Close the log file
        objLogFile.Close
    End If
Next

WScript.Echo "Finished: software.vbs has finished. Check event log for errors."
WScript.Quit(0)

回复

使用道具 举报


ADVERTISEMENT

发表于 13-1-2017 01:15 PM | 显示全部楼层
可以先看你export的file吗?有可能可以用excel command就做到。
回复

使用道具 举报

 楼主| 发表于 16-1-2017 12:02 PM | 显示全部楼层
chili1984 发表于 13-1-2017 01:15 PM
可以先看你export的file吗?有可能可以用excel command就做到。

export的file。
感谢

Untitled.png
回复

使用道具 举报

发表于 16-1-2017 02:16 PM | 显示全部楼层

應該沒問題.
你用excel開csv時,可能要用tab as a separator.
祝順利
回复

使用道具 举报

 楼主| 发表于 17-1-2017 01:52 PM | 显示全部楼层
yan13 发表于 16-1-2017 02:16 PM
應該沒問題.
你用excel開csv時,可能要用tab as a separator.
祝順利

什么意思?可以解释详细点吗?
回复

使用道具 举报

发表于 17-1-2017 02:02 PM | 显示全部楼层
NgSzeyin2005 发表于 17-1-2017 01:52 PM
什么意思?可以解释详细点吗?

excel 2007 - Data > from textdelimited > tab > finish

Capture.PNG
Capture1.PNG

评分

参与人数 1人气 +5 收起 理由
NgSzeyin2005 + 5 谢谢分享

查看全部评分

回复

使用道具 举报

Follow Us
 楼主| 发表于 17-1-2017 05:00 PM | 显示全部楼层
yan13 发表于 17-1-2017 02:02 PM
excel 2007 - Data > from textdelimited > tab > finish

原来我还是个Excel白痴。
谢谢你啦~

回复

使用道具 举报

发表于 18-1-2017 05:54 AM | 显示全部楼层
NgSzeyin2005 发表于 17-1-2017 05:00 PM
原来我还是个Excel白痴。
谢谢你啦~

不客氣
術業有專精,改天也有會向你請教的時候.
回复

使用道具 举报


ADVERTISEMENT

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 29-3-2024 12:41 PM , Processed in 0.071572 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表