Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 508
  • Last Modified:

Need VB or HTA to create a printer then delete it

I have a custom scenario where a user needs to connect to an IPP printer (http://99.99.99.99:631), then the user will print to the printer, then will need to disconnect or delete the printer.  So I need either a VB script or an HTA that the user can execute that will create the printer, then provide a desktop button that the user can click to disconnect or delete the printer after the user is done printing to it.  
0
murryc
Asked:
murryc
  • 3
1 Solution
 
raiERBCommented:
Try this vb script
0
 
raiERBCommented:
Code was not attached to my message... here the script:
On Error Resume Next
Dim wshNet     : Set wshNet = CreateObject("WScript.Network")
Dim strPrinter : strPrinter = "http://99.99.99.99:631"

wshNet.SetDefaultPrinter strPrinter
If Err Then
  wshNet.AddWindowsPrinterConnection strPrinter
  wshNet.SetDefaultPrinter strPrinter
End If
On Error GoTo 0

Open in new window

0
 
raiERBCommented:
To remove the same printer use the following code:


On Error Resume Next
Dim wshNet     : Set wshNet = CreateObject("WScript.Network")
Dim strPrinter : strPrinter = "http://99.99.99.99:631"

wshNet.RemovePrinterConnection strPrinter, True, True
On Error GoTo 0

Open in new window

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.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now