Solved

how to change output file name vbs

Posted on 2011-03-08
4
528 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
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 …

895 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

12 Experts available now in Live!

Get 1:1 Help Now