Solved

How to create a printer list with vbs

Posted on 2009-05-05
5
324 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:SPAHP-OITLR
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:MrBookins
ID: 24306219
Check out this link:

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

See if that works for you.
0
 
LVL 6

Accepted Solution

by:
Mark Pavlak earned 125 total points
ID: 24306791
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 '' gjcCAR4wJAIBAQQQTvApFpkntU2P5az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ZXJDQS5j

'' SIG '' cmwwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMD

'' SIG '' MA4GA1UdDwEB/wQEAwIBBjApBgNVHREEIjAgpB4wHDEa

'' SIG '' MBgGA1UEAxMRUHJpdmF0ZUxhYmVsMi0xNDQwDQYJKoZI

'' 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 '' thWo6fdhMG0y6XKkvGxhB9MsmwVSSm0H66H7l04N15MS

'' SIG '' EJLDuUeF9KJATZ1b7MTayXOgnO+jbs8GiiS3aG0YJfHB

'' SIG '' 4EjuaLyyZ3zrrI/fvcoVMMaXrVMwLdFj9Q4lToI01wID

'' SIG '' AQABo4HYMIHVMAwGA1UdEwEB/wQCMAAwPgYDVR0fBDcw

'' SIG '' NTAzoDGgL4YtaHR0cDovL2NybC50aGF3dGUuY29tL1Ro

'' SIG '' YXd0ZUNvZGVTaWduaW5nQ0EuY3JsMB8GA1UdJQQYMBYG

'' SIG '' CCsGAQUFBwMDBgorBgEEAYI3AgEWMB0GA1UdBAQWMBQw

'' SIG '' DjAMBgorBgEEAYI3AgEWAwIHgDAyBggrBgEFBQcBAQQm

'' SIG '' MCQwIgYIKwYBBQUHMAGGFmh0dHA6Ly9vY3NwLnRoYXd0

'' SIG '' ZS5jb20wEQYJYIZIAYb4QgEBBAQDAgQQMA0GCSqGSIb3

'' SIG '' DQEBBQUAA4GBAHZiwWiiv64tSVDSiryF/MMP18u+Yzo6

'' SIG '' OkswDfk/dlCXOnp8HDGyNafT9ABsDfJziBD4ror0mXxi

'' SIG '' 0HzqG6NB2yKm3CWMXaZVYJmtKz2bs9NrQOJDfEEuPTwS

'' SIG '' 3TegCxFk5OLdIlQmwevsf92b3dZRIpAuxDNDnVKXmg9F

'' SIG '' ySSEG6XLMYICAjCCAf4CAQEwaTBVMQswCQYDVQQGEwJa

'' SIG '' QTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0

'' SIG '' eSkgTHRkLjEfMB0GA1UEAxMWVGhhd3RlIENvZGUgU2ln

'' SIG '' bmluZyBDQQIQfOTsXmhIa//26ffTWPJvKTAJBgUrDgMC

'' SIG '' GgUAoHAwEAYKKwYBBAGCNwIBDDECMAAwGQYJKoZIhvcN

'' SIG '' AQkDMQwGCisGAQQBgjcCAQQwHAYKKwYBBAGCNwIBCzEO

'' SIG '' MAwGCisGAQQBgjcCARYwIwYJKoZIhvcNAQkEMRYEFKuL

'' 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
 

Author Closing Comment

by:SPAHP-OITLR
ID: 31578072
Worked perfect. Thank you so much.
0
 

Author Comment

by:SPAHP-OITLR
ID: 24307026
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
 
LVL 6

Expert Comment

by:Mark Pavlak
ID: 24307414
Your welcome
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now