Solved

Need VB or HTA to create a printer then delete it

Posted on 2010-11-30
3
499 Views
Last Modified: 2012-05-10
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
Comment
Question by:murryc
[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
  • 3
3 Comments
 
LVL 3

Expert Comment

by:raiERB
ID: 34246011
Try this vb script
0
 
LVL 3

Expert Comment

by:raiERB
ID: 34246014
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
 
LVL 3

Accepted Solution

by:
raiERB earned 500 total points
ID: 34246091
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS ACCESS 2010 Clear Form Button 4 73
Classic ASP - Display returned sql output parameter 9 58
Add Log to powershell Script 14 31
Writing reports to a script 7 34
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
If you ever consider purchasing any Daossoft Software Products, DON'T expect any meaningful support - This article should convince you why!
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

710 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