Date: Fri, 24 May 2013 09:55:38 +0200
Quote:
- The Official Scripting Guys Forum! Forum (recent threads)
Having a problem reading the output file of printui.dll.PrintUIEntry with vbscript
http://services.social.microsoft.com/feeds/FeedItem?feedId=00000000-0000-0000-0000-000000000000&itemId=8df799b4-03d0-48bc-8375-f15ae3a6e56e&title=Having+a+problem+reading+the+output+file+of++printui.dll.PrintUIEntry+with+vbscript&uri=http%3a%2f%2fsocial.technet.microsoft.com%2fForums%2fen-US%2fITCG%2fthread%2f8df799b4-03d0-48bc-8375-f15ae3a6e56e%2f&k=eYoL%2bBkLYmi6q%2fCcHtFRrTkKAvM01bTe9Ra81EAsUcI%3d
Text:
I have a script to execute the command rundll32 printui.dll,PrintUIEntry /ge /c\\workstation /f c:\temp\printers.txt
This part works fine. I can open and read the file in notepad, no problem.
I then try to read the file in vbscript, and it can not read it. BUT, if I open the file in notepad, copy and paste to a new document, the script works fine. I have tried to copy it to a new document, append it, open and close it, with vbscript to no avail.
I also noticed the txt file created by printui is larger than the one I create manually.
Heres the sub the writes the file and that reads the file.
I put the timers in during troubleshooting. To make sure the file had time to create.
Sub WorkStationPrinters
strComputer = "\\" & ComputerName.value
Cmd = "rundll32 printui.dll,PrintUIEntry /ge /c" & strComputer &" /f c:\printers.txt"
Set oShell = CreateObject("Wscript.Shell")
oShell.Run Cmd,0,1
idTimer4 = window.setTimeout("ReadWSPrinters", 5000, "VBScript")
End Sub
Sub ReadWSPrinters
Const FOR_READING = 1
Const FOR_WRITING = 2
Const FOR_APPENDING = 8
strFileName = "c:\temp\printers.txt"
Set objFS = CreateObject("Scripting.FileSystemObject")
If objFS.FileExists(strFileName) Then
Set objTS = objFS.OpenTextFile(strFileName, FOR_READING)
strContents = objTS.ReadAll
objTS.Close
arrLines = Split(strContents, vbNewLine)
For Each strLine In arrLines
If InStr(strLine,"Printer") > 0 Then
msgbox Mid(strLine,15)
End If
Next
'objFS.DeleteFile strFileName
Else
msgbox "Can not find " & strFileName
End If
window.clearTimeout(idTimer4)
End Sub
The c:\temp\printers.txt file looks something like this
Printer Name: \\server1\printer
Server Name: \\server1
Printer Name: \\server1\printer2
Server Name: \\server1
Thanks
Brian
Via FeedShow.com