Solved

Create text file from VBSript

Posted on 2009-05-14
7
837 Views
Last Modified: 2012-05-07
I have been tasked with writing a VBScript that is being used to determine if our corporate antivirus definitions are over 7 days old.  This will be  used by our management platform to automatically generate an alert.  I have been able to get it where it generates the output into a pop up window, but I need it to create a text file called vipreage.txt on the C: drive.  I have been trying  to find an answer to this but scripting has never been a strong suit of mine.  Any help would be greatly appreciated.
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.GetFile("c:\Program Files\Sunbelt Software\SBEAgent\Definitions\defver.txt")

wscript.echo DateDiff("d", objFile.DateLastModified, Now())

Open in new window

0
Comment
Question by:sdipietro
  • 3
  • 2
  • 2
7 Comments
 
LVL 5

Expert Comment

by:satheeshm
Comment Utility
Hi,

You are near to solution. you can create text file using file system object. Check the below code sample.

dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("c:\test.txt",true)
fname.WriteLine("Hello World!")
fname.Close
set fname=nothing
set fs=nothing
0
 

Author Comment

by:sdipietro
Comment Utility
satheeshm,

Would that just be added below the existing text?
0
 
LVL 9

Assisted Solution

by:gregcmcse
gregcmcse earned 62 total points
Comment Utility
Replace the "wscript.echo" line with these lines:
set myFile = objFSO.CreateTextFile("c:\vipreage.txt",True)
myFile.WriteLine DateDiff("d", objFile.DateLastModified, Now())
myFile.Close
set myFile = Nothing
 
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 5

Accepted Solution

by:
satheeshm earned 63 total points
Comment Utility
no.. it creates a new file. you want create new file or you want to append to an existing text file.

to create a new file use the below code. I added code to your existing code.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\Program Files\Sunbelt Software\SBEAgent\Definitions\defver.txt")
wscript.echo DateDiff("d", objFile.DateLastModified, Now())
dim fname
set fname=fs.CreateTextFile("c:\vipreage.txt",true)
fname.WriteLine("Hello World!") \\ Change this to what ever you want to write into the file
fname.Close
set fname=nothing
set objFSO=nothing
0
 
LVL 5

Expert Comment

by:satheeshm
Comment Utility
okay.. if you dont want alert remove the echo from that code
0
 
LVL 9

Expert Comment

by:gregcmcse
Comment Utility
If you want to append to your output file rather than overwrite it everytime, change it to this:
ForAppending = 8
set myFile = objFSO.OpenTextFile("c:\vipreage.txt", ForAppending,True)
myFile.WriteLine DateDiff("d", objFile.DateLastModified, Now())
myFile.Close
set myFile = Nothing
0
 

Author Comment

by:sdipietro
Comment Utility
Thanks Guys!  I was able to get the script working by using what you both gave me.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

14 Experts available now in Live!

Get 1:1 Help Now