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

以下是我找到的脚本:

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,_
     strEntry1b,strValue1
  End If
  If strValue1 <> "" Then
    WScript.Echo VbCrLf & "Display Name: " & strValue1
  End If
  objReg.Getstringvalue HKLM,_
   strEntry2,strValue2
  If strValue2 <> "" Then
    WScript.Echo "Install Date: " & strValue2
  End If
  objReg.GetDWORDValue HKLM,_
   strEntry3,intValue3
  objReg.GetDWORDValue HKLM,_
   strEntry4,intValue4
  If intValue3 <> "" Then
     WScript.Echo "Version: " & intValue3 & "." & intValue4
  End If
  objReg.GetDWORDValue HKLM,_
   strEntry5,intValue5
  If intValue5 <> "" Then
    WScript.Echo "Estimated Size: " & round(intValue5/1024,3) & " megabytes"
  End If
Next

解决方法

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

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

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

...

f.Close
'End of Script

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

大佬总结

以上是大佬教程为你收集整理的csv – 我需要将VBS WScript.Echo输出写入text或cvs全部内容,希望文章能够帮你解决csv – 我需要将VBS WScript.Echo输出写入text或cvs所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。