Solved

Need a write to text file solution . . .

Posted on 2006-06-12
2
889 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now