Create txt with default printer name in VBS

4

Good morning, I have the following script.

Set oShell = CreateObject("WScript.Shell")
strValue = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
strPrinter = oShell.RegRead(strValue)
strPrinter = Split(strPrinter, ",")(0)

I would like to create a file .txt with the name of the variable strPrinter . I use BGinfo to tell which default printer it has server\modelo\ip .

It would be interesting to just bring the name of the printer, so I'm going to generate a txt file and use the filename as reference for printer information.

How to create a txt file with variable name? I can also solve by putting the information inside the txt file. For example, creating a file named "Printer.txt"

    
asked by anonymous 20.12.2016 / 12:16

1 answer

1

Solved! Here's a solution:

Dim fso, MyFile, printer
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\printer.txt", True)
MyFile.WriteLine(strPrinter)
MyFile.Close
    
21.12.2016 / 11:35