Solved

how to change output file name vbs

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This is about my first experience with programming Arduino.

749 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