[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to create a printer list with vbs

Posted on 2009-05-05
5
Medium Priority
?
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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 '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Ja
'' 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

650 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