How to create a printer list with vbs

I need some help writing a vbs script to recreate a text file that has a list of printers. Using a batch script, it runs: cscript %systemroot%\system32\prnmngr.vbs -l > "c:\documents and settings\%username%\Desktop\printers.txt"
From here the text file is full of unneeded information (see attached). What I would like to have is a vbs file that reads through the file and pulls only the printer name and puts it into a new text file.
printers.txt
SPAHP-OITLRAsked:
Who is Participating?
 
Mark PavlakConnect With a Mentor Commented:
EASY!  This will allow you to browse for the source file.  Create an output file in the root of c: named printers.txt ( this can be changed on line 10 to whatever you want.
Dim sFileName,sTempLine
Dim oFso,oInfile,oOutFile
Const ForReading = 1
 
 
 
sFileName = BrowseForFile("c:\")
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oInfile = oFso.OpenTextFile (sFileName,ForReading)
Set oOutFile = oFso.CreateTextFile ("C:\Printers.txt",True)
Do Until oInfile.AtEndOfStream
	sTempLine = oInfile.ReadLine
		If InStr(sTempLine,"Printer name ") <> 0 Then
			oOutFile.WriteLine Replace(sTempLine,"Printer name ","")
		End If 
Loop
 
 
WScript.Echo sFileName
Function BrowseForFile (path)
Dim objDialog
 
Set objDialog = CreateObject("UserAccounts.CommonDialog")
With objDialog
	.Filter = "Text Files|*.txt"
	.Flags = &H80000
	.FilterIndex = 1
	.InitialDir = path
End With
intResult = objDialog.ShowOpen
 
If intResult = 0 Then
    Wscript.Quit
Else
    BrowseForFile = objDialog.FileName
End If
End function
 
'' SIG '' Begin signature block
'' SIG '' MIIJxAYJKoZIhvcNAQcCoIIJtTCCCbECAQExCzAJBgUr
'' SIG '' DgMCGgUAMGcGCisGAQQBgjcCAQSgWTBXMDIGCisGAQQB
'' SIG '' gjcCAR4wJAIBAQQQTvApFpkntU2P5azhDxfrqwIBAAIB
'' SIG '' AAIBAAIBAAIBADAhMAkGBSsOAwIaBQAEFNmaIEWIjvx6
'' SIG '' bfX9QAKLLq40w8VBoIIHLjCCA04wggK3oAMCAQICAQow
'' SIG '' DQYJKoZIhvcNAQEFBQAwgc4xCzAJBgNVBAYTAl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YJKoZI
'' SIG '' hvcNAQEFBQADgYEAdrKc7hOfG/YtNJKURXM03I5rLlz8
'' SIG '' TH2J68No8deZDy4dF8i1Fou+zYoFBvIZSToDWwXJII5t
'' SIG '' UuF2gaDDZYoiZ+QcU1M3Rr+81y/re57QFEVsQCEI4l11
'' SIG '' dmYwHvTfgoovvfOiDL8d258UoppyN02wd0joSj8JzlUZ
'' SIG '' LO/mByThr+wwggPYMIIDQaADAgECAhB85OxeaEhr//bp
'' SIG '' 99NY8m8pMA0GCSqGSIb3DQEBBQUAMFUxCzAJBgNVBAYT
'' SIG '' AlpBMSUwIwYDVQQKExxUaGF3dGUgQ29uc3VsdGluZyAo
'' SIG '' UHR5KSBMdGQuMR8wHQYDVQQDExZUaGF3dGUgQ29kZSBT
'' SIG '' aWduaW5nIENBMB4XDTA4MDYwNTAwMDAwMFoXDTA5MDUz
'' SIG '' MDIzNTk1OVowgaAxCzAJBgNVBAYTAlVTMRcwFQYDVQQI
'' SIG '' Ew5Ob3J0aCBDYXJvbGluYTEXMBUGA1UEBxMORWxpemFi
'' SIG '' ZXRoIENpdHkxKDAmBgNVBAoTH0dhdGV3YXkgRmluYW5j
'' SIG '' aWFsIEhvbGRpbmdzIEluYy4xCzAJBgNVBAsTAklUMSgw
'' SIG '' JgYDVQQDEx9HYXRld2F5IEZpbmFuY2lhbCBIb2xkaW5n
'' SIG '' cyBJbmMuMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
'' SIG '' CgKCAQEA1asfrPULdZzPm7QfWBbbg+QXqtJBXAe2BDne
'' SIG '' tIBRGkTKPXqiruEvC4gahuHiLXWRFviusVNCMynbbDLo
'' SIG '' /UzUKflSXJIabAknmCYBPEgn7j9O6xhdWRPNb11TV2Wu
'' SIG '' rR9+EuiZ1EXNMmtKqMrtJEtoqe+Bsu//mQuhCjsHhMne
'' SIG '' mvXs6P5/F+YqcAlAwsQgOnqmMo/KbHZ/rPYrI6fB7zMq
'' SIG '' thWo6fdhMG0y6X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IhvcNAQkEMRYEFKuL
'' SIG '' Ee6LgxoioO5Tt0UM3C7ET1caMA0GCSqGSIb3DQEBAQUA
'' SIG '' BIIBAMZtXF5YYCDmu7XrNi2amaKhobtwE+m3/dWPJatE
'' SIG '' bfOI8di7kItiKlVRhM62pELdB1r+F0GCYHqDg0TMHsyL
'' SIG '' iqS/pjuEPrIx8JGNb1KoP9lC4FIx85JpXJH5j1cq6EbZ
'' SIG '' Phm5Lr5LZEdN9IIPUAzE0QZOS9JLl54vUAf12F3ZArn+
'' SIG '' 3mfjBB0eeBYGtZujxSVwwHre/BjPyedpeeZCCmJX8ZhQ
'' SIG '' ktlzAvwHruC+bh/51RbcDOs4+lEL9oNlJx7bjJO94PEf
'' SIG '' 2TAjYlDPPo77h7JvXrdQpKa1s+LFwVxstCs+UZsz7et6
'' SIG '' vAGuiEbjnA27Kx5NNyPWMrI2qOUgCfrtIx90nPU=
'' SIG '' End signature block

Open in new window

0
 
MrBookinsCommented:
Check out this link:

http://anandpv.spaces.live.com/blog/cns!AFCCA5892B178862!1694.entry

See if that works for you.
0
 
SPAHP-OITLRAuthor Commented:
Worked perfect. Thank you so much.
0
 
SPAHP-OITLRAuthor Commented:
Jfinner Thank you the script it worked well. Was wondering if you could alter it so it grabs the printer.txt file from a predefined location opposed to having to search for it. This script will need to have no end user interaction. Thank you in advance.
0
 
Mark PavlakCommented:
Your welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.