Solved

Need a write to text file solution . . .

Posted on 2006-06-12
2
891 Views
Last Modified: 2012-05-05
Currently this is my script:

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("floyd_adamsxp","ALEX_KHAZAN_XP")
For Each strComputer In arrComputers
   WScript.Echo
   WScript.Echo "=========================================="
   WScript.Echo "Computer: " & strComputer
   WScript.Echo "=========================================="

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
        WScript.Echo "Name: " & objItem.Name
       WScript.Echo "Model: " & objItem.Model
Next
Set colSMBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
    Wscript.Echo "Asset Tag: " & objSMBIOS.SMBIOSAssetTag
Next
Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")
For each objBIOS in colBIOS
     Wscript.Echo "Serial Number: " & objBIOS.SerialNumber
   Next
Next


Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
      WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
      Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
      & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function

What I would like to do is export the data to a text file, but I've been having a difficult time doing it for some reason.  Please help.  Lots of points!
0
Comment
Question by:campbe07
  • 2
2 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 500 total points
ID: 16885578
Hi,

How about something like...

Dim objFileSystemObject
Dim objFSO_TextFile
Dim strLog_Filename

strLog_Filename                         = "C:\Output.txt"

Set objFileSystemObject                    = CreateObject("Scripting.FileSystemObject")

If Not (objFileSystemObject.FileExists(strLog_Filename)) Then
   Set objFSO_TextFile                    = objFileSystemObject.CreateTextFile(strLog_Filename)
   Set objFSO_TextFile                    = Nothing
End If  

Set objFSO_TextFile                    = objFileSystemObject.OpenTextFile(strLog_Filename, 2) ' 2 = ForWriting
'Set objFSO_TextFile                    = objFileSystemObject.OpenTextFile(strLog_Filename, 8) ' 8 = ForAppending

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("floyd_adamsxp","ALEX_KHAZAN_XP")
For Each strComputer In arrComputers

objFSO_TextFile.WriteLine ""
objFSO_TextFile.WriteLine "=========================================="
objFSO_TextFile.WriteLine "Computer: " & strComputer
objFSO_TextFile.WriteLine "=========================================="

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
        objFSO_TextFile.WriteLine "Name: " & objItem.Name
        objFSO_TextFile.WriteLine "Model: " & objItem.Model
   Next
Set colSMBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
        objFSO_TextFile.WriteLine "Asset Tag: " & objSMBIOS.SMBIOSAssetTag
Next
Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")
For each objBIOS in colBIOS
    objFSO_TextFile.WriteLine "Serial Number: " & objBIOS.SerialNumber
   Next
Next

objFSO_TextFile.Close

Set objFSO_TextFile                    = Nothing
Set objFileSystemObject                    = Nothing

Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
     WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
     Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
     & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function

BFN,

fp.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16890112
I trust that suggestion met your requirements.

Thanks for closing the question.

BFN,

fp.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question