user2766426
user2766426

Reputation: 21

Trying to redirect stdout to a file

I'd like to send the stdout to a logfile with a datestamp and location for each printer.

On Error resume Next 

Dim objNetwork, StdIn, StdOut

'Initialize the printer connections object
Set objNetwork = CreateObject("WScript.Network")  
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut

'Connect each printer
objNetwork.AddWindowsPrinterConnection "\\server\pr01"
objNetwork.AddWindowsPrinterConnection "\\server\pr02"
objNetwork.AddWindowsPrinterConnection "\\server\pr03"

'Remove old printers
'objNetwork.RemoveWindowsPrinterConnection "\\old_server\printer_1"
'objNetwork.RemoveWindowsPrinterConnection "\\old_server\printer_2

Upvotes: 2

Views: 3023

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200193

If you want to do it from within the script open a file instead of using WScript.StdOut:

Set fso = CreateObject("Scripting.FileSystemObject")
...
Set StdOut = fso.OpenTextFile("C:\path\to\your.txt", 2, True)

...

StdOut.Close

Otherwise redirect the output created by the script to a file:

C:\>cscript //NoLogo script.vbs >C:\path\to\your.txt

Timestamps can be printed like this:

StdOut.WriteLine Now

I'm not sure what exactly you mean by "location".

Upvotes: 1

Related Questions