Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Read txt file.

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61084
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Read txt file.
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Read txt file. - 6/5/2008 5:14:39 AM   
  jcarver_14

 

Posts: 31
Score: 0
Joined: 6/4/2008
From: Cincinnati
Status: offline
Hi,

I'm sure this is possible but im very new to VBScript so im kinda lost and im hoping someone can help me with it.

Im trying to use the script below to write this file to a list of computers.  I would like to have it read a list of computer names from a text and insert it where it says computer name.  And to top it off i would like it to rite a list of computer names to a txt file that it could not connect to.  Any ideas?

Set FSO = CreateObject("Scripting.FileSystemObject")
Set Destination = fso.CreateTextFile ("\\Computername\C$\Documents and Settings\All Users\Desktop\Find My Service Tag", True)
Destination.WriteLine Set WshNetwork = WScript.CreateObject("WScript.Network")
Destination.WriteLine WScript.Echo "Service Tag = " & WshNetwork.ComputerName
Destination.Close

 
 
Post #: 1
 
 RE: Read txt file. - 6/5/2008 11:33:20 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
here's a better start, or search the forum or google. I suppose if you lookup ping you will find better examples[I have a few just lazy to lookk right now]


      

_____________________________

"You start coding. I'll go find out what they want."

(in reply to jcarver_14)
 
 
Post #: 2
 
 RE: Read txt file. - 6/10/2008 1:42:24 AM   
  jcarver_14

 

Posts: 31
Score: 0
Joined: 6/4/2008
From: Cincinnati
Status: offline
I couldnt get this to work.  It looks like it might be reading the txt file but not writing anyting.  any idea waht im doing wrong.  Here is the code i was working with.

Option Explicit
'Declare variables
Dim strComputer
Dim arrComputers
Dim TxtFile
Dim objTextFile
Dim strNextLine
Dim objLogFile
Dim OverwriteExisting
Dim WshShell : Set WshShell = CreateObject("Wscript.Shell")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim WshSysEnv : Set WshSysEnv = WshShell.Environment("Process")
Dim SysDrive : SysDrive = WshShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
Dim SourceL:SourceL = "C:\test.txt"                                              ----- this is the file i would like ti to copy
Dim LogFile:LogFile = sysDrive & "\Filelog.txt"
Dim DestFile:DestFile = "C:\test.txt"
On Error Resume Next
Const ForAppending = 8
Const ForReading = 1
TxtFile = sysDrive & "\wslist.txt"                                                       ----I put this file in the root and i think it is supposed to contain the computer names
  
'Copy & verify file
Set objLogFile = objFSO.OpenTextFile(LogFile, 8, true)
Set objTextFile = objFSO.OpenTextFile (TxtFile, 1)
  TxtFile = objTextFile.ReadAll
  objTextFile.Close
  objLogFile.Close
  arrComputers = Split(TxtFile, vbCrLf)
For Each strComputer in arrComputers
  Wscript.Echo strComputer
      objFSO.CopyFile SourceL & DestFile, "\\"& strComputer & "\c$\", OverwriteExisting
  If objFSO.FileExists(SysDrive & "\" & DestFile) Then
      objLogFile.Write strComputer
      objLogFile.WriteLine
  Else
      objFSO.CopyFile SourceL , SysDrive & "\", True
  End If
Next
 
'Clean up & quit
Set objFSO = Nothing
Set objTextFile = Nothing

thanks again for you help

< Message edited by jcarver_14 -- 6/10/2008 1:59:48 AM >

(in reply to gdewrance)
 
 
Post #: 3
 
 RE: Read txt file. - 6/10/2008 7:59:53 AM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi jcarver_14,

first you switch on error hiding:

    On Error Resume Next

then you close the output file

    objLogFile.Close

So

   objLogFile.Write strComputer

must (silently) fail.

Regards

ehvbs

(in reply to jcarver_14)
 
 
Post #: 4
 
 RE: Read txt file. - 6/23/2008 5:17:35 AM   
  jcarver_14

 

Posts: 31
Score: 0
Joined: 6/4/2008
From: Cincinnati
Status: offline
Come on now.  I thought this was going to be a fairly simpe one.  And after 108 hits and 3 replies I realized I wasnt getting any help so I asked one of my good friends for help, a network manager, thats right network... not programer, and he helped me.  But sense noone here cares to help I will post the script I came up with, maybe it will help someone....


      

In case your like me and you dont know much about vbs heres how this works and what you need to do.

How it works:

This reads a list of computer names from a txt file.  It then pings each one.  If it does not ping it writes the computer name to a txt file called Failed.txt.  If it does ping it will copy the file you specify to the destination you specified on the computer then write the computer name to a text file named Completed.txt.

What you need to do:

Because this script works out of a folder you will need to create a folder for it.  ex. Copy Files... and place the script into it.  Then create a txt file named Computer Names.txt inside the same folder and enter the computer names into it.  Open the vbs script for editing.  you will need to edit line 21.  If you can place the file to be copied into the folder as well that works great.  Just replace %file% with the file name.  be sure to include the extention.  If you would like to keep the folder in its location just replace it with the path. ex. C:\folder\test.txt.  Then you will need to edit the destination.  it is curently set to \\computername\C$\ and is in line 21 as well.  When the script has finished it will display a messsage box letting you know.

(in reply to ehvbs)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Read txt file. Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts