Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to change output file name vbs

Posted on 2011-03-08
4
Medium Priority
?
557 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 2000 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

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!

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

885 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