WSHNetwork.RemoveNetworkDrive error when deleting a printer

Posted on 2006-05-15
Last Modified: 2010-08-05
Basically I get a WSHNetwork.RemoveNetworkDrive error when removing a printer using a vbscript on one of our on others, just this one.
Question by:dcarrion

    Author Comment

    vbscripting up to date. almost identical to the one that works.
    LVL 26

    Accepted Solution

    remove the printer using RemoveNetworkDrive?

    Should you use RemovePrinterConnection?

    Option Explicit
    Dim objNetwork, strUNCPrinter

    strUNCPrinter = "\\Server\printer"
    Set objNetwork = CreateObject("WScript.Network")
    on error resume next
    objNetwork.RemovePrinterConnection strUNCPrinter


    Author Comment

    Yep that's what i'm doin :)
    no go...

    Author Comment

    Okay Hold on

    Only happens when I try to remove local printers that are attatched via terminal services...see script below.

    Set oNetwork = WScript.CreateObject("WScript.Network")
    Set oPrinter = oNetwork.EnumPrinterConnections
    For iCount = 0 to oPrinter.Count - 1 Step 2

    Result = InStr(oPrinter.Item(iCount+1), "Session")

    If Result > 0 then

    oNetwork.RemovePrinterConnection oPrinter.Item(iCount+1),True,False


    End if


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now