Solved

Create text file from VBSript

Posted on 2009-05-14
7
841 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
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 5

Expert Comment

by:satheeshm
ID: 24388333
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
ID: 24388361
satheeshm,

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

Assisted Solution

by:gregcmcse
gregcmcse earned 62 total points
ID: 24388478
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
satheeshm earned 63 total points
ID: 24388517
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
ID: 24388527
okay.. if you dont want alert remove the echo from that code
0
 
LVL 9

Expert Comment

by:gregcmcse
ID: 24388668
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
ID: 24420954
Thanks Guys!  I was able to get the script working by using what you both gave me.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

732 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