Alright, here's what I'm faced with, and I'm not a VB coder (I'm the guy who does PHP and some C++, so VB is quite a new ballgame for me).
What I have is a very large network environment where we are replacing some proprietary software, and it requires reinstallation of existing printers/drivers/ports. The existing installation of the printers is using the "Generic / Text Only" driver. So I figured it wouldn't be difficult, using prnadmin.dll, to delete the printer based on it's driver. (These systems only have one "Generic / Text Only" printer installed also).
So here's what I did, and it failed, and I don't know why. It is based off the code found here (link)
dim oMaster
set oMaster = CreateObject("PrintMaster.PrintMaster.1")
set oPrinter = CreateObject("Printer.Printer.1")
oPrinter.DriverName = "Generic / Text Only"
oMaster.PrinterDel oPrinter
That comes up with a context error, so I figured you had to specify it by the PrinterName property. Now in prnadmin.dll tools pack, there is a vbs script called prnmgr.vbs that will list all printers on yours system, so I attempted to modify that method, and it failed miserably (download dll and vbs scripts here)
dim oMaster
set oMaster = CreateObject("PrintMaster.PrintMaster.1")
for each oPrinter in oMaster.Printers("")
if oPrinter.DriverName = "Generic / Text Only" then
oMaster.PrinterDel oPrinter
end if
That does nothing. However, it's almost identical to the code in the prnmgr.vbs script. I replaced the if statement to display the DriverName and it doesn't display anything.
There's gotta be a way to do this, I'm just not a VB programmer to find it. Any help?
You guys have always been great here! Thanks in advance!
PS: Here is the ListPrinters code from the prnmgr.vbs script:
function ListPrinters(strServer)
on error resume next
DebugPrint kDebugTrace, "In ListPrinter"
dim oMaster
dim oPrinter
dim iRetval
set oMaster = CreateObject("PrintMaster.PrintMaster.1")
for each oPrinter in oMaster.Printers(strServer)
if Err.Number = kErrorSuccess then
wscript.echo ""
wscript.echo "ServerName : " & oPrinter.ServerName
wscript.echo "PrinterName : " & oPrinter.PrinterName
wscript.echo "ShareName : " & oPrinter.ShareName
wscript.echo "DriverName : " & oPrinter.DriverName
wscript.echo "PortName : " & oPrinter.PortName
wscript.echo "Comment : " & oPrinter.Comment
wscript.echo "Location : " & oPrinter.Location
wscript.echo "SepFile : " & oPrinter.SepFile
wscript.echo "PrintProcesor : " & oPrinter.PrintProcessor
wscript.echo "DataType : " & oPrinter.DataType
wscript.echo "Parameters : " & oPrinter.Parameters
wscript.echo "Attributes : " & CSTR(oPrinter.Attributes)
wscript.echo "Priority : " & CSTR(oPrinter.Priority)
wscript.echo "DefaultPriority : " & CStr(oPrinter.DefaultPriority)
wscript.echo "StartTime : " & CStr(oPrinter.StartTime)
wscript.echo "UntilTime : " & CStr(oPrinter.UntilTime)
wscript.echo "Status : " & CStr(oPrinter.Status)
wscript.echo "Jobc Count : " & CStr(oPrinter.Jobs)
wscript.echo "AveragePPM : " & CStr(oPrinter.AveragePPM)
Err.Clear
else
wscript.echo "Unable to list printers, error: 0x" & _
Hex(Err.Number) & ". " & Err.Description
ListPrinters = kErrorFailure
exit function
end if
next
wscript.echo "Success listing printers"
ListPrinters = kErrorSuccess
end function