Solved

Need a write to text file solution . . .

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 54
Validating VB6 Function 19 56
using Access 8 58
Adding to a VBA? 6 60
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

929 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

12 Experts available now in Live!

Get 1:1 Help Now