Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Csv 我需要将VBS WScript.Echo输出写入文本或cvs_Csv_Text_Vbscript_Echo_Wsh - Fatal编程技术网

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

Csv 我需要将VBS WScript.Echo输出写入文本或cvs,csv,text,vbscript,echo,wsh,Csv,Text,Vbscript,Echo,Wsh,我正在尝试编写一个VBScript,它将以文本文件或csv格式列出系统上所有已安装的应用程序。我能够找到一个现有的代码来列出所有的软件(包括名称、版本、日期和大小)。当我目前运行它,因为我发现它的回声出现作为主机回声弹出窗口。我需要向vbs添加什么才能将每个回声输出到文件中?我相信这很容易,但我似乎找不到解决办法 下面是我找到的脚本: Dim fso Set fso = WScript.CreateObject("Scripting.Filesystemobject") ' List All I

我正在尝试编写一个VBScript,它将以文本文件或csv格式列出系统上所有已安装的应用程序。我能够找到一个现有的代码来列出所有的软件(包括名称、版本、日期和大小)。当我目前运行它,因为我发现它的回声出现作为主机回声弹出窗口。我需要向vbs添加什么才能将每个回声输出到文件中?我相信这很容易,但我似乎找不到解决办法

下面是我找到的脚本:

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
Dim fso
设置fso=WScript.CreateObject(“Scripting.Filesystemobject”)
'列出所有已安装的软件
常数HKLM=&H80000002'HKEY\U本地\U机器
strComputer=“”
strKey=“软件\Microsoft\Windows\CurrentVersion\Uninstall\”
strEntry1a=“显示名称”
strEntry1b=“QuietDisplayName”
strEntry2=“安装日期”
strengthy3=“VersionMajor”
strengthy4=“VersionMinor”
strEntry5=“估计大小”
Set objReg=GetObject(“winmgmts://”&strComputer&_
“/root/default:StdRegProv”)
objReg.EnumKey HKLM、strKey、arrSubkeys
Echo“已安装的应用程序”和VbCrLf
对于ArrSubkey中的每个strSubkey
intRet1=objReg.GetStringValue(HKLM、strKey和strSubkey、_
强度1A,标准值1)
如果intRet1为0,则
objReg.GetStringValue HKLM、strKey和strSubkey、_
强度1b,标准值1
如果结束
如果标准值为1“”,则
WScript.Echo VbCrLf&“显示名称:”&strValue1
如果结束
objReg.GetStringValue HKLM、strKey和strSubkey、_
强度2,标准值2
如果标准值为2“”,则
WScript.Echo“安装日期:”&strValue2
如果结束
objReg.GetDWORDValue HKLM、STREY和strSubkey、_
强度3,intValue3
objReg.GetDWORDValue HKLM、STREY和strSubkey、_
强度4,intValue4
如果intValue3为“”,则
Echo“版本:”&intValue3&“&intValue4
如果结束
objReg.GetDWORDValue HKLM、STREY和strSubkey、_
强度5,intValue5
如果intValue5“则
Echo“估计大小:&&Round(intValue5/1024,3)和“兆字节”
如果结束
下一个

一种方法是通过
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

Skarykid-我知道您在大约6个月前收到并回答了这个问题,但我一直在寻找类似的脚本&没有太多成功地得到我想要的。我已经修改了您提供的脚本,添加了Ansgar的建议&我自己的一些代码,以生成以下增强版本

此脚本将生成本地计算机上安装的所有32位和64位应用程序的列表文本文件,然后在记事本中打开生成的文件

希望这有助于你或任何其他人遇到这个问题

'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
”listapps.vbs
'生成一个文本文件,列出本地计算机上安装的所有32位和64位应用程序
'===================================================================================
'声明常量、变量和数组
'---------------------------------------
'注册表项和值
常数HKLM=&H80000002'HKEY\U本地\U机器
调光键(1)
arrKeys(0)=“软件\Microsoft\Windows\CurrentVersion\Uninstall”
arrKeys(1)=“软件\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall”
strComputer=“”
strEntry1a=“显示名称”
strEntry1b=“QuietDisplayName”
strEntry2=“发布者”
strEntry3=“安装日期”
strEntry4=“估计大小”
strEntry5=“显示版本”
'创建输出文件
Dim objShell、objShellEnv、strComputerName、objFso
设置objShell=WScript.CreateObject(“WScript.Shell”)
设置objShellEnv=objShell.Environment(“进程”)
strComputerName=objShellEnv(“ComputerName”)
设置objFso=WScript.CreateObject(“Scripting.FileSystemObject”)
Set outputFile=objFso.CreateTextFile(strComputerName&“.txt”,True)
'===================================================================================
Set objReg=GetObject(“winmgmts://”和strComputer&“/root/default:StdRegProv”)
'打印标题(如果您不想在输出文件中使用标题,请注释掉下面的行)
'outputFile.WriteLine“Name”&vbTab&“Publisher”&vbTab&“Installed On”&vbTab&“Size”&vbTab&“Version”&VbCrLf
对于i=0到1
'检查以确保注册表项存在
intCheckKey=objReg.EnumKey(HKLM、arrKeys(i)、arrSubkeys)
如果intCheckKey=0,则
对于ArrSubkey中的每个strSubkey
intReturn=objReg.GetStringValue(HKLM、arrKeys(i)和strSubkey、strEntry1a、strValue1)
如果返回0,那么
objReg.GetStringValue HKLM、arrKeys(i)和strSubkey、strEntry1b、strValue1
如果结束
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、STRVALUE 5
如果标准值为1“”,则
outputFile.WriteLine strValue1&vbTab&strValue2&vbTab&strValue3&vbTab&strValue4&vbTab&strValue5
如果结束
下一个
如果结束
下一个
'关闭输出文件
outputFile.Close
'启动输出文件以供查看
运行“notepad.exe”&strComputerName&“.txt”
"清理,退出"
Set objShell=Nothing
设置objFso=Nothing

除了Ansgar的顶级答案之外,还有

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


允许VBS脚本创建输出文件,而不要求目标中已有空白文件

阅读并了解这一危险的错误信息的原因。我仔细阅读了这两个链接,但不明白这是“危险”的原因。它隐藏了.OpenTextFile的第三个“create”参数,并错误地暗示.CreateTextFile的第二个参数是io模式。但第一个参数不是gerendasi的语句和
Set f = fso.CreateTextFile("C:\output.txt", 2)