Solved

how to change output file name vbs

Posted on 2011-03-08
4
533 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
[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
  • 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

Technology Partners: 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!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 …

752 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