Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Output script results to text file

Posted on 2004-10-27
15
Medium Priority
?
2,204 Views
Last Modified: 2009-10-08
I'm not a big vbscript guy, so I'm not sure what I'm doing here.  I have a vb script (a .vbs file on my pc) running this script to get the serial # of the pc:

On Error Resume Next
StrComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem in colItems
      Wscript.echo "SerialNumber: " & objItem.SerialNumber
      Next

However, this just outputs the serial # to the screen.  I need to put these serial numbers into a text file.  So I added some lines to do this:

Open ("C:\results.txt") For Output As #1
Write #1, "SerialNumber: " & objItem.SerialNumber

But I keep getting an error:  Expected End of Statement on the Open line right at the "For" part.

Am I doing this right?  I'm sure it's just something stupid I'm doing, any help is appreciated, thanks!
0
Comment
Question by:ericb1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
  • +1
15 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 12424764
try

Open "C:\results.txt" For Output As #1
Print #1, "SerialNumber: " & objItem.SerialNumber
Close #1
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 12424777
or you can open for append if you want to add to the file:

Open "C:\results.txt" For append As #1
Print #1, "SerialNumber: " & objItem.SerialNumber
Close #1
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12424780
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS", , 48)

Open "C:\results.txt" For Output As #1

For Each objItem In colItems
     Print #1, "SerialNumber: " & objItem.SerialNumber
Next

Close #1
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:ericb1
ID: 12424838
I still get the same thing:  a compilation error:  Expected End of Statement on line 5,  Character 23 which is the F in For Output statement.

I'm running this directly from my pc as a .vbs file, not sure if that makes a difference?  Thanks!
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 12424930
use fso:

Dim fso,txtFile
Set fso = CreateObject("Scripting.FileSystemObject")

Set txtFile = fso.CreateTextFile("C:\results.txt", True)
    txtFile.WriteLine "SerialNumber: " & objItem.SerialNumber
    txtFile.Close
   
Set txtFile = Nothing
Set fso = Nothing
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 12424961
or maybe:

Dim fso,txtFile

On Error Resume Next
StrComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)

Set fso = CreateObject("Scripting.FileSystemObject")
Set txtFile = fso.CreateTextFile("C:\results.txt", True)

For Each objItem in colItems
     txtFile.WriteLine "SerialNumber: " & objItem.SerialNumber
next

txtFile.Close
Set txtFile = Nothing
Set fso = Nothing
0
 
LVL 14

Expert Comment

by:aelatik
ID: 12424972
Don't use anything. If its plain VBS just PIPE it to a file like :

C:\cscript yourfile.vbs >> result.txt
0
 
LVL 14

Expert Comment

by:aelatik
ID: 12425021
Hiding the scripting logo would be like :

C:\cscript yourfile.vbs >> result.txt //nologo

note : In batch or scripting the ECHO command parses the text to screen. The parsed text can always be PIPED to a textfile.
0
 

Author Comment

by:ericb1
ID: 12425104
no dice.  The fso method seemed to work, it didn't give any errors, but the txt file wasn't created.
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 12425376
If you remove the On Error line,does it cause an error?
0
 

Author Comment

by:ericb1
ID: 12425437
Oops, yes it does.  I get an error on creating the text file:  ActiveX component can't create object: 'Scripting.FileSystemObject'
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 12425545
0
 

Author Comment

by:ericb1
ID: 12425549
Not sure how to allow the file to be created, do I have to allow ActiveX permissions somewhere?  Any help is appreciated, thanks!
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 200 total points
ID: 12425589
I think you might be missing the scripting runtime files (Scrrun.dll) which is included in the above download link.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12425635
vinnyd79 has the correct answer.  Remove "On Error Resume Next" to see what if anything is causing an error for you...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Suggested Courses

618 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