gpt4 book ai didi

csv - 我需要将VBS WScript.Echo输出写入文本或cvs

转载 作者:行者123 更新时间:2023-12-04 05:18:43 27 4
gpt4 key购买 nike

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

以下是我找到的脚本:

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运行脚本并将输出重定向到文件:

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

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

关于csv - 我需要将VBS WScript.Echo输出写入文本或cvs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17194375/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com