Create txt with Default name Printer in VBS

Asked

Viewed 1,738 times

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 variable name strPrinter. Utilise BGinfo to inform which standard printer however it brings server\modelo\ip.

It would be interesting to bring only the printer name, for this I will generate a txt file and use the file name as reference for the printer information.

How to create a txt file with the variable name? I can also resolve by placing the information inside the txt file. Creating for example a file called "Printer.txt"

  • Filesystemobject https://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84). aspx What is the specific difficulty?

  • Example: In my code the variable strPrinter = HPPPS001 Brotherxxxx. I want it to be placed inside a file. txt "which will be created" from the script. Would you insert this information into a . txt created by vbs. What am I going to do with it? Use bginfo to inform current user, machine name, IP and etc.. I’m including the default printer for the user to see... I can bring it straight from the registry, but it brings like this: "HPPPS001 Brotherxxxx, Brother 2270, 192.168.0.X"

1 answer

1

Solved! Follows solution:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.