csv – 我需要将VBS WScript.Echo输出写入text或cvs

前端之家收集整理的这篇文章主要介绍了csv – 我需要将VBS WScript.Echo输出写入text或cvs前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试编写一个VBScript,它将在文本文件或csv中列出系统上所有已安装的应用程序.我能够找到现有代码列出所有软件(包括名称,版本,日期和大小).当我正在运行它时,因为我发现它回显了主机回声弹出.我需要添加什么来使其将每个回声输出文件?我相信这很容易,但我似乎无法找到解决方案.

以下是我找到的脚本:

  1. Dim fso
  2. Set fso = WScript.CreateObject("Scripting.Filesystemobject")
  3. ' List All Installed Software
  4.  
  5.  
  6.  
  7.  
  8.  
  9. Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
  10. strComputer = "."
  11. strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
  12. strEntry1a = "DisplayName"
  13. strEntry1b = "QuietDisplayName"
  14. strEntry2 = "InstallDate"
  15. strEntry3 = "VersionMajor"
  16. strEntry4 = "VersionMinor"
  17. strEntry5 = "EstimatedSize"
  18.  
  19. Set objReg = GetObject("winmgmts://" & strComputer & _
  20. "/root/default:StdRegProv")
  21. objReg.EnumKey HKLM,strKey,arrSubkeys
  22. WScript.Echo "Installed Applications" & VbCrLf
  23. For Each strSubkey In arrSubkeys
  24. intRet1 = objReg.GetStringValue(HKLM,strKey & strSubkey,_
  25. strEntry1a,strValue1)
  26. If intRet1 <> 0 Then
  27. objReg.GetStringValue HKLM,_
  28. strEntry1b,strValue1
  29. End If
  30. If strValue1 <> "" Then
  31. WScript.Echo VbCrLf & "Display Name: " & strValue1
  32. End If
  33. objReg.GetStringValue HKLM,_
  34. strEntry2,strValue2
  35. If strValue2 <> "" Then
  36. WScript.Echo "Install Date: " & strValue2
  37. End If
  38. objReg.GetDWORDValue HKLM,_
  39. strEntry3,intValue3
  40. objReg.GetDWORDValue HKLM,_
  41. strEntry4,intValue4
  42. If intValue3 <> "" Then
  43. WScript.Echo "Version: " & intValue3 & "." & intValue4
  44. End If
  45. objReg.GetDWORDValue HKLM,_
  46. strEntry5,intValue5
  47. If intValue5 <> "" Then
  48. WScript.Echo "Estimated Size: " & Round(intValue5/1024,3) & " megabytes"
  49. End If
  50. Next

解决方法

解决此问题的一种方法是通过cscript.exe运行脚本并将输出重定向文件
  1. cscript.exe //Nologo "C:\path\to\your.vbs" >"C:\output.txt"

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

  1. Dim fso
  2. Set fso = WScript.CreateObject("Scripting.Filesystemobject")
  3. Set f = fso.OpenTextFile("C:\output.txt",2)
  4.  
  5. ...
  6.  
  7. f.Close
  8. 'End of Script

并用f.WriteLine替换每次出现的WScript.Echo.

猜你在找的HTML相关文章