使用VB Script将客户端安装的软件信息存储到MySQL中?

时间:2013-11-27 12:16:07

标签: mysql vbscript

我要求将已安装的应用程序信息导入MySQL数据库,在网上搜索了几个小时后,我得到了vb脚本,如下所示。它应该有两个功能

  1. 它应该将数据保存到文本文件中
  2. 第二是它应该写入MySQL数据库。
  3. 我得到了第一个但是第二个却抛出了错误

    Object doesn't support this property or method : 'Execute'
    
    code : 800A01B6
    

    我使用的代码是

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.CreateTextFile("c:\scripts\software.tsv", True)
    
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colSoftware = objWMIService.ExecQuery _
      ("Select * from Win32_Product")
    
    objTextFile.WriteLine "Caption" & vbtab & _
      "Description" & vbtab & "Identifying Number" & vbtab & _
      "Install Date" & vbtab & "Install Location" & vbtab & _
      "Install State" & vbtab & "Name" & vbtab & _ 
      "Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _
        & "Version" 
    
    Dim objConnection
    Dim objRecordSet
    Set objConnection = CreateObject("ADODB.Connection")
    Set objRecordSet = CreateObject("ADODB.Recordset")
    connectionString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=testing;User=root; Password=******;"
    objConnection.Open  connectionString  
    
    For Each objSoftware in colSoftware
      objTextFile.WriteLine objSoftware.Caption & vbtab & _
      objSoftware.Description & vbtab & _
      objSoftware.IdentifyingNumber & vbtab & _
      objSoftware.InstallDate2 & vbtab & _
      objSoftware.InstallLocation & vbtab & _
      objSoftware.InstallState & vbtab & _
      objSoftware.Name & vbtab & _
      objSoftware.PackageCache & vbtab & _
      objSoftware.SKUNumber & vbtab & _
      objSoftware.Vendor & vbtab & _
      objSoftware.Version
    
    objRecordSet.Execute "INSERT INTO Computers (Caption, Description, IdentifyingNumber, InstallDate2,InstallLocation,InstallState,Name,PackageCache,SKUNumber, Vendor, Version)"&"VALUES (objSoftware.Caption & vbtab &, objSoftware.Description & vbtab &, objSoftware.IdentifyingNumber & vbtab &, objSoftware.InstallDate2 & vbtab &, objSoftware.InstallLocation & vbtab &, objSoftware.InstallState & vbtab &, objSoftware.Name & vbtab &, objSoftware.PackageCache & vbtab &, objSoftware.SKUNumber & vbtab &, objSoftware.Vendor & vbtab &, objSoftware.Version)", objConnection, adOpenStatic, adLockOptimistic
    
    Next
    objTextFile.Close
    objConnection.Close
    

1 个答案:

答案 0 :(得分:0)

错误是由Recordset对象没有.Execute方法引起的。理论上,您应该使用Recordset.Open或Connection.Execute来执行(参数)查询/语句。

看看你在INSERT声明中所造成的混乱,我建议你将。{TXT数据LOAD DATA INFILE导入你的DBMS。

请参阅:

  1. load data infile
  2. execute