Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Script Problem with Writing File

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Script Problem with Writing 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 >>
 Script Problem with Writing File - 5/23/2005 4:23:16 AM   
  Rushman

 

Posts: 5
Score: 0
Joined: 5/20/2005
From: USA
Status: offline
Anyone,

I was wondering why I can't get this script to write to the text file that I have listed. Here is the script:

Option Explicit

Const ForWriting = 2

on error resume Next

Dim WshShell, NAVDefKey, RegSplit, SystemNAVDef, formattedDEF, vavDef, strCommandLine
Set WshShell = WScript.CreateObject("WScript.Shell")

NAVDefKey = WshShell.RegRead("HKLM\SOFTWARE\Symantec\SharedDefs\NAVCORP_70")

RegSplit = Split(NAVDefKey,"\")
SystemNAVDef = RegSplit(5)

WScript.Echo SystemNavDef


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\avlisting.txt", ForWriting)
objFile.WriteLine (SystemNavDef)
objFile.Close

What this script does is it checks a reg entry for Anti-Virus information and I want to write it to a Text file located on the C:\ drive. When I run the scipt I get the echo but the text file is not being written to. I am perplexed because if I write this script as 2 different scripts and pass in the info that I want it works fine. Yet it doesn't this way. Any help is greatly appreciated.

Tim
 
 
Post #: 1
 
 Re: Script Problem with Writing File - 5/23/2005 5:52:45 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
change
objFile.WriteLine (SystemNavDef)
to
objFile.WriteLine SystemNavDef

(in reply to Rushman)
 
 
Post #: 2
 
 Re: Script Problem with Writing File - 5/23/2005 6:19:59 AM   
  Rushman

 

Posts: 5
Score: 0
Joined: 5/20/2005
From: USA
Status: offline
Tried that. It didn't work. Thanks for the suggestion though. :-) Anything else?

Tim

(in reply to Rushman)
 
 
Post #: 3
 
 Re: Script Problem with Writing File - 5/23/2005 7:00:28 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
either comment out the option explicit or dim each variable before using it. Also you'll never get an error if you use on error resume next.

you didnt dim the objfso or objfile variables.

(in reply to Rushman)
 
 
Post #: 4
 
 Re: Script Problem with Writing File - 5/23/2005 7:03:59 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
also you need a true at the end of your fso.opentext command

finished (working) code:

      

(in reply to Rushman)
 
 
Post #: 5
 
 Re: Script Problem with Writing File - 5/23/2005 7:11:46 AM   
  Rushman

 

Posts: 5
Score: 0
Joined: 5/20/2005
From: USA
Status: offline
Hey folks... Thank you so much for your help. I can't believe I forgot to dim out a couple of my variables. Doh... Also what does the 'TRUE' at the end of the OpenTextFile mean?

Again, Thanks for all your information and help.

Tim

(in reply to Rushman)
 
 
Post #: 6
 
 Re: Script Problem with Writing File - 5/23/2005 3:11:46 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
it creates the file if it doesnt exist

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsmthopentextfile.asp

(in reply to Rushman)
 
 
Post #: 7
 
 
 
  

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 >> Script Problem with Writing 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