我需要将VBS WScript.Echo输出写入文本或cvs [英] I need to write VBS WScript.Echo output to text or cvs

查看:810
本文介绍了我需要将VBS WScript.Echo输出写入文本或cvs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个VBScript,它将以文本文件或csv的形式列出系统上所有已安装的应用程序.我能够找到一个列出所有软件的现有代码(包括名称,版本,日期和大小).当我当前运行它时,我发现它随着主机回显弹出而出现回显.我需要在vb中添加什么以使其将每个回显输出到文件?我确信这很容易,但是我似乎找不到解决方法.

I am attempting to write a VBScript that will list all of the installed application on a system in a text file or csv. I was able to find an existing code to list all of the software (including name, version, date, and size). When I currently run it as I have found it the echo comes up as a host echo pop up. What do I need to add to the vbs to make it output each of the echos to a File? I am sure this is easy, but i can't seem to find a solution.

下面是我找到的脚本:

Dim fso
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
' List All Installed Software





Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry2 = "InstallDate"
strEntry3 = "VersionMajor"
strEntry4 = "VersionMinor"
strEntry5 = "EstimatedSize"

Set objReg = GetObject("winmgmts://" & strComputer & _
 "/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
WScript.Echo "Installed Applications" & VbCrLf
For Each strSubkey In arrSubkeys
  intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
   strEntry1a, strValue1)
  If intRet1 <> 0 Then
    objReg.GetStringValue HKLM, strKey & strSubkey, _
     strEntry1b, strValue1
  End If
  If strValue1 <> "" Then
    WScript.Echo VbCrLf & "Display Name: " & strValue1
  End If
  objReg.GetStringValue HKLM, strKey & strSubkey, _
   strEntry2, strValue2
  If strValue2 <> "" Then
    WScript.Echo "Install Date: " & strValue2
  End If
  objReg.GetDWORDValue HKLM, strKey & strSubkey, _
   strEntry3, intValue3
  objReg.GetDWORDValue HKLM, strKey & strSubkey, _
   strEntry4, intValue4
  If intValue3 <> "" Then
     WScript.Echo "Version: " & intValue3 & "." & intValue4
  End If
  objReg.GetDWORDValue HKLM, strKey & strSubkey, _
   strEntry5, intValue5
  If intValue5 <> "" Then
    WScript.Echo "Estimated Size: " & Round(intValue5/1024, 3) & " megabytes"
  End If
Next

推荐答案

一种解决方法是通过cscript.exe运行脚本并将输出重定向到文件:

One way to go about this would be to run the script via cscript.exe and redirect the output to a file:

cscript.exe //NoLogo "C:\path\to\your.vbs" >"C:\output.txt"

如果要修改脚本以将其输出写入文件,而不考虑其运行方式,则需要添加代码以打开/关闭输出文件:

If you want to modify the script to write its output to a file regardless of how it's run, you need to add code for opening/closing the output file:

Dim fso
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
Set f = fso.OpenTextFile("C:\output.txt", 2)

...

f.Close
'End of Script

,并将每次出现的WScript.Echo替换为f.WriteLine.

and replace each occurrence of WScript.Echo with f.WriteLine.

这篇关于我需要将VBS WScript.Echo输出写入文本或cvs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆