I need to write VBS WScript.Echo output to text or cvs

I am trying to write VBScript, which will indicate the entire installed application in the system in a text file or csv. I managed to find the existing code to display all the software (including name, version, date and size). When I currently run it, since I found it, an echo appears when a host echo appears. What do I need to add to vbs so that it outputs each of the echo files to a file? I am sure this is easy, but I cannot find a solution.

Below script I found:

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 
+6
source share
3 answers

One way to do this is to run the script through 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 your output to a file no matter how it is executed, you need to add code to open / close the output file:

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

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

+13
source

Scarikid. I know what you got and answered it almost 6 months ago, but I was looking for a similar script and did not have much success, achieving exactly what I wanted. I modified the proposed script, added Ansgar suggestions and a little custom code to come up with the next version.

This script will create a tabular text file of all 32-bit and 64-bit applications installed on the local computer, and then open the resulting file in notepad.

Hope this helps you or anyone else to come across this thread.

 'listapps.vbs 'Generates a text file listing all 32bit & 64bit apps installed on the local machine '=================================================================================== 'Declare constants, variables and arrays '--------------------------------------- 'Registry keys and values Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE Dim arrKeys(1) arrKeys(0) = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" arrKeys(1) = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" strComputer = "." strEntry1a = "DisplayName" strEntry1b = "QuietDisplayName" strEntry2 = "Publisher" strEntry3 = "InstallDate" strEntry4 = "EstimatedSize" strEntry5 = "DisplayVersion" 'Create the output file Dim objShell, objShellEnv, strComputerName, objFso Set objShell = WScript.CreateObject("WScript.Shell") Set objShellEnv = objShell.Environment("Process") strComputerName = objShellEnv("ComputerName") Set objFso = WScript.CreateObject("Scripting.FileSystemObject") Set outputFile = objFso.CreateTextFile(strComputerName & ".txt", True) '=================================================================================== Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv") 'Print header (comment out the line below if you do not want headers in your output file) 'outputFile.WriteLine"Name" & vbTab & "Publisher" & vbTab & "Installed On" & vbTab & "Size" & vbTab & "Version" & VbCrLf For i = 0 to 1 'Check to ensure registry key exists intCheckKey = objReg.EnumKey(HKLM, arrKeys(i), arrSubkeys) If intCheckKey = 0 Then For Each strSubkey In arrSubkeys intReturn = objReg.GetStringValue(HKLM, arrKeys(i) & strSubkey, strEntry1a, strValue1) If intReturn <> 0 Then objReg.GetStringValue HKLM, arrKeys(i) & strSubkey, strEntry1b, strValue1 End If objReg.GetStringValue HKLM, arrKeys(i) & strSubkey, strEntry2, strValue2 objReg.GetStringValue HKLM, arrKeys(i) & strSubkey, strEntry3, strValue3 objReg.GetDWORDValue HKLM, arrKeys(i) & strSubkey, strEntry4, strValue4 objReg.GetStringValue HKLM, arrKeys(i) & strSubkey, strEntry5, strValue5 If strValue1 <> "" Then outputFile.WriteLine strValue1 & vbTab & strValue2 & vbTab & strValue3 & vbTab & strValue4 & vbTab & strValue5 End If Next End If Next 'Close the output file outputFile.Close 'Launch output file for review objShell.run "notepad.exe " & strComputerName & ".txt" 'Clean up and exit Set objShell = Nothing Set objFso = Nothing 
+2
source

In addition to Ansgar's first rating, changing

 Set f = fso.OpenTextFile("C:\output.txt", 2) 

to

 Set f = fso.CreateTextFile("C:\output.txt", 2) 

Allows a VBS script to create output files, rather than requiring that an existing empty file be already in the target location.

0
source

Source: https://habr.com/ru/post/947663/


All Articles