Solved

how to change output file name vbs

Posted on 2011-03-08
4
527 Views
Last Modified: 2012-05-11
i have a script that i am working with and i need the output file to be something like cert_computername.csv i have tried many suggestions and cant get it to work just right, currently it just outputs Certificates.csv


Option Explicit
Dim oTrans
Set oTrans = CreateObject("Scripting.FileSystemObject")
Dim oTransF
Set oTransF = oTrans.OpenTextFile("Certificates.csv", 2, True)
Dim objMMC
Set objMMC = CreateObject("MMC20.Application")
objMMC.Show
objMMC.Load("\\servername\Certificates\certmgr.msc")
Dim objDoc
Set objDoc = objMMC.Document
Dim objSN
Set objSN = objDoc.ScopeNamespace
Dim objRoot
Set objRoot = objDoc.RootNode
Dim objEvtVwrNode
Set objEvtVwrNode = objSN.GetChild(objRoot)
objSN.Expand(objEvtVwrNode)
Dim objView
Set objView = objDoc.ActiveView
On Error Resume Next
Dim objNode
Set objNode = Nothing
Set objNode = objSN.GetChild(objEvtVwrNode)
If (objNode Is Nothing) then
 Wscript.echo "Unable to get Event Viewer child node, end of programm."
 Wscript.quit
End If
Do Until (objNode Is Nothing)
 objSN.Expand(objNode)
 objView.ActiveScopeNode = objNode
 Dim BerDoss
 Set BerDoss = Nothing
 Set BerDoss = objSN.GetChild(objNode)
 Do Until (BerDoss Is Nothing)
  objSN.Expand(BerDoss)
  objView.ActiveScopeNode = BerDoss
  Dim objList
  Set objList = objView.ListItems
  Dim objItem
  For Each objItem In objList
   Dim str
   str = objView.CellContents(objItem, 1)
   If (str <> "Error") Then
    Dim vLigne
    Dim I
    vLigne = objNode.Name + " ; " + BerDoss.Name
    For I = 1 To 20
     vLigne = vLigne + " ; " + objView.CellContents(objItem, I)
    Next
    oTransF.writeline vLigne
   End If
  Next
  Dim objSib2
  Set objSib2 = Nothing
  Set objSib2 = objSN.GetNext(BerDoss)
  Set BerDoss = objSib2
 Loop
 Dim objSib
 Set objSib = Nothing
 Set objSib = objSN.GetNext(objNode)
 Set objNode = objSib
Loop
oTransF.Close
MsgBox "finished certs"
Wscript.quit

Open in new window

0
Comment
Question by:adamshields
  • 2
4 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 35072661
just change this:

   Set oTransF = oTrans.OpenTextFile("Certificates.csv", 2, True)

to this:

   Set oTransF = oTrans.OpenTextFile("cert_computername.csv", 2, True)
0
 
LVL 3

Author Comment

by:adamshields
ID: 35072744
by computername i mean i want it to grab the actual computername like in a batch file %computername%
0
 
LVL 3

Author Comment

by:adamshields
ID: 35072898
currently i am just running a batch file to just rename the certificates.csv file to cert_%computername%.csv after the script has completed
0
 
LVL 11

Accepted Solution

by:
TheGorby earned 500 total points
ID: 35073228
Just put the first 2 lines of this code in before you use the environment variable, and change the output filename as shown in the last line:
Set oShell = CreateObject( "WScript.Shell" ) 
sName=oShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

Set oTransF = oTrans.OpenTextFile("Cert_" & sName & ".csv", 2, True)

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

747 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

13 Experts available now in Live!

Get 1:1 Help Now