WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Printer Controller

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Delete the Local Printers Mapped to a WinNT Server

Keywords: 	 delete local printers mapped

Question:

I wrote up some code to delete all network printers from a local PC. It works fine on Windows 98. It works on Win2k's local printers if they are mapped from novell, but NOT when they are mapped from our WinNT servers.

My code is simple (perhaps too simple), it retrieves the name of the local printers, and if the printer port isn't LPT1: then it deletes the printer. Appearantly, the name of a locally installed network printer on Start/settings/printers is different than the returned name of a locally installed network printer. For example: the local name may be "HP8100N on SERVER", but the name returned from the extender was "\\SERVER\HP8100N". And when we ran the code, it deleted "\\SERVER\HP8100N" from our SERVER along with every other network printer on our server.

My question is: How do I delete locally installed network printers without deleting the printers from the server?

An example my used code is below:

AddExtender("WWPRT34i.DLL")
printers = pGetPrtList(1)

a = ItemCount(printers, @TAB)
For j = 1 to a 
indv_ptrs = ItemExtract(j, printers, @TAB)
If ItemExtract(2, indv_ptrs, "|") == "LPT1:" then next
pDelPrinter(ItemExtract(1, indv_ptrs, "|"))
Next

Answer:

The following code will It will delete all printers except those on the LPT1: port.
AddExtender("WWPRT34i.DLL")

printers = pGetPrtList(1)
a = ItemCount(printers, @TAB)

For j = 1 to a 
   indv_ptrs = ItemExtract(j, printers, @TAB)
   If ItemExtract(2, indv_ptrs, "|") == "LPT1:" then next
   prtr=ItemExtract(1, indv_ptrs, "|")

   if WinVersion(4) == 4  && StrIndex(ItemExtract(1, indv_ptrs, "|"),"\",0,@backscan); NT/2000/XP
      midslashptr=StrIndex(prtr,"\",0,@backscan)
      srv=strsub(prtr,1,midslashptr-1)
      p = ItemExtract(2, indv_ptrs, "|")
      pause(srv,p)
      pDelPrtConn(srv,p)  
   else
      pause("",prtr)
      pDelPrinter(prtr)
   endif
Next

Article ID:   W15072
File Created: 2017:07:28:13:58:37
Last Updated: 2002:09:05:13:49:25