Csv 在两个.bat文件中重新构造代码

Csv 在两个.bat文件中重新构造代码,csv,batch-file,text,vbscript,Csv,Batch File,Text,Vbscript,我已经开发了一个程序(1),分批编码,名为info.bat: @echo OFF setlocal enableextensions enabledelayedexpansion SET file="%~dp0%computername%.csv" If Exist %file% Del %file% echo %Version_tool%,ID,Asset,Sys_Type,Model,NHC Asset,New Sys Type,New Model,New Sys Asset,Domain

我已经开发了一个程序(1),分批编码,名为
info.bat

@echo OFF
setlocal enableextensions enabledelayedexpansion 
SET file="%~dp0%computername%.csv"
If Exist %file% Del %file%
echo %Version_tool%,ID,Asset,Sys_Type,Model,NHC Asset,New Sys Type,New Model,New Sys Asset,Domain,DIR,Site,Team,Location,Post,Name,Postcode,Local Printers,Network Printers,Eth_MACs,Wifi_MACs,Phone_MAC,Software Needed,OTHER_ASSET,OS_VER,Hostname,Software_Notes,Other_Notes,IGEL_REC>>%file%
rem  ========= Other code =========
echo ,%ID%,%serialnumber%,PC,%model%,,,,,%userdomain%,Unknown,,,,,,,%Local_Printers%,!network_printers!,!Eth_MACs!,!Wifi_MACs!,!Phone_MACs!,Not Used,%system%,%osname%,%Hostname%,,,%IGEL REC%>> %file%

SET file2="%~dp0%computername%-programs.txt"
If Exist %file2% Del %file2%
start /b cmd /k "cscript //nologo programs_02.vbs >> %file2%"
echo Batch Tool should finish in a few seconds ...
  • 存储有关计算机的信息
  • 操作信息并将详细信息输出到
    %ComputerName%.csv
    文件
  • 然后调用
    .vbs
    文件(2),并将已安装程序的列表输出到
    %ComputerName%-programs.txt
    文件,该文件与
    .csv
    文件位于同一目录中
  • .vbs
    完成时,批处理文件结束,用户将看到一个Cmd窗口,准备执行下一个命令
接下来手动启动另一个程序
StripSoftware.bat(3)

  • 它创建
    %ComputerName%-要检查的程序.txt
  • 添加操作系统版本和
    %ComputerName%
  • 检查
    %ComputerName%-programs.txt
    中的条目
  • 取出不需要的匹配项(使用findstr和开关)
  • 删除空行
  • 排序结果升序
  • 然后将它们放入
    %ComputerName%-要检查的程序.txt
目标:

  • 我需要使用
    %ComputerName%-程序中的软件条目(每个软件名称一行)来检查.txt
    ,将它们连接在一起,然后将它们放入
    .csv
    文件中的
    软件所需的
    列中
输出:

  • 需要的输出是
    .csv
    文件,或者最好是
    .xlsx
    文件,第一行有以下标题,第二行有适用信息
.csv示例:

v34,ID,Asset,Sys_Type,Model,NHC Asset,New Sys Type,New Model,New Sys Asset,Domain,DIR,Site,Team,Location,Post,Name,Postcode,Local Printers,Network Printers,Eth_MACs,Wifi_MACs,Phone_MAC,Software Needed,OTHER_ASSET,OS_VER,Hostname,Software_Notes,Other_Notes,IGEL_REC
,,ABCDEFG,PC,A123,,,,,XXXX,Unknown,,,,,,, , ,||"XX-XX-XX-XX-XX-XX"|"Disabled",,,Not Used,ABCDEFG,Win XP Pro,ABCDEFG,,,
info.bat的部分内容

@echo OFF
setlocal enableextensions enabledelayedexpansion 
SET file="%~dp0%computername%.csv"
If Exist %file% Del %file%
echo %Version_tool%,ID,Asset,Sys_Type,Model,NHC Asset,New Sys Type,New Model,New Sys Asset,Domain,DIR,Site,Team,Location,Post,Name,Postcode,Local Printers,Network Printers,Eth_MACs,Wifi_MACs,Phone_MAC,Software Needed,OTHER_ASSET,OS_VER,Hostname,Software_Notes,Other_Notes,IGEL_REC>>%file%
rem  ========= Other code =========
echo ,%ID%,%serialnumber%,PC,%model%,,,,,%userdomain%,Unknown,,,,,,,%Local_Printers%,!network_printers!,!Eth_MACs!,!Wifi_MACs!,!Phone_MACs!,Not Used,%system%,%osname%,%Hostname%,,,%IGEL REC%>> %file%

SET file2="%~dp0%computername%-programs.txt"
If Exist %file2% Del %file2%
start /b cmd /k "cscript //nologo programs_02.vbs >> %file2%"
echo Batch Tool should finish in a few seconds ...
.vbs
文件的内容:

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 & 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 
Const HKLM=&H80000002'HKEY_本地_机器
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、strengthY1a、strValue1)
如果intRet1为0,则
objReg.GetStringValue HKLM、strKey和strSubkey、strength1b、strrvalue1
如果结束
如果标准值为1“”,则
WScript.Echo VbCrLf和strValue1
如果结束
objReg.GetStringValue HKLM、strKey和strSubkey、strength2、strrvalue 2
如果标准值为2“”,则
“WScript.Echo”安装日期:&strValue2
如果结束
objReg.GetDWORDValue HKLM、STREY和strSubkey、strEntry3、intValue3
objReg.GetDWORDValue HKLM、STREY和strSubkey、strEntry4、intValue4
如果intValue3为“”,则
Echo“版本:”&intValue3&“&intValue4
如果结束
objReg.GetDWORDValue HKLM、STREY和strSubkey、strEntry5、INTVALUE 5
如果intValue5“则
“WScript.Echo”估计大小:“&Round(intValue5/1024,3)和“MB”
如果结束
下一个
问题:

  • 按照当前方式,代码是结构化的
    info.bat
    在创建
    .txt
    文件之前创建
    .csv
    文件,并且
    %ComputerName%-要检查.txt
    的程序中提供了所需的
    软件的值(例如
    Adobe Flash | Windows修补程序
    )。因此,很难用第二行所需的
    软件的值更新
    .csv
建议的解决办法:(*)

  • 我开始认为应该首先调用
    .vbs
    文件,在第一个
    .bat
    文件中创建
    %ComputerName%-programs.txt
    ,然后在第二个
    .bat
    文件中创建
    %ComputerName%-programs-tocheck.txt
    的功能,然后使用该信息和其他信息创建
    %ComputerName%.csv
问题:

1) 希望大家对拟议的解决办法有想法、意见和看法


2) 关于比建议的解决方案更好的解决方案的建议。

不清楚您想要什么。这是我的标准职务。那我给你看些东西

开始-所有程序-附件-右键单击命令提示符并选择以管理员身份运行。键入(或通过在命令提示窗口中单击鼠标右键并选择“粘贴”来复制和粘贴)。表格格式的类型

wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:htable
或者以某种形式

wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:hform
它将在桌面上创建一个html文件

注意

这不是一个完整的列表。这是仅随Windows Installer安装的产品。没有什么特性适合所有的东西

然而,正如我在上一篇文章中所说,几乎所有的东西都列在注册表中

所以要在命令提示符中查看它

reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s
或者在文件中

reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s>"%userprofile%\desktop\WindowsUninstall.txt"
以不同的格式在记事本中查看

单击开始-所有程序-附件-右键单击命令提示符并选择以管理员身份运行。键入Regedit并导航到

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
右键单击卸载键并选择导出。如果另存为reg文件(还有文本文件,它们的文本格式略有不同),则需要右键单击该文件并选择“编辑”以查看该文件

查看Windows更新

wmic /output:"%userprofile%\desktop\WindowsUpdate.html" qfe  get /format:htable
下面是一个VBS脚本,用于获取已安装的程序、排序和筛选器

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set rs = CreateObject("ADODB.Recordset")
Set wshshell = CreateObject("wscript.shell")
Set Outp = Wscript.Stdout

ComputerName=WshShell.ExpandEnvironmentStrings("%Computername%")

'Build database with Computername and Softwarename

    With rs
        .Fields.Append "ComputerName", 201, 5000 

        .Fields.Append "Txt", 201, 5000 
        .Open

        'Get list installed programs

        Set colItems = objWMIService.ExecQuery("Select * From Win32_Product")

        'Add to database

        For Each objItem in colItems
            .AddNew
            .Fields("ComputerName").value = ComputerName
            .Fields("Txt").value = objItem.Name
            .UpDate
        Next
        'Sort Database on software name

        'Sort and filter it - Softwarename acending (Txt) and filter only those starting M

        .Sort = "Txt ASC"
        .Filter = "Txt like 'm*'"

        'write out to a CSV

        Do While not .EOF
            Outp.writeline .Fields("ComputerName").Value & "," & .Fields("Txt").Value

            .MoveNext
        Loop
    End With
使用

cscript //nologo <path to vbs file> > OUTPUTFILE
所以有三个地方可以丢弃物品。在WMI
中选择

Set colItems = objWMIService.ExecQuery("Select * from Win32_Product where Name='Microsoft LifeCam'")
并且在过滤器中使用类似的语法,如上所示


另外,在写回的时候,你可以比较一下,不要写你不想要的。

我的问题中有什么不清楚的?让我知道,我可以提供更多信息和/或更新问题。你想要的输出,我不得不猜测。您的问题描述了您的程序的一般交互。我已更新了问题。请在重读后告知您是否还有其他需要澄清的内容。但您想要什么输出,而不是您认为应该如何生成输出,