PRB: You Receive Error Message If You Use AddWindowsPrinterConnection Method to Add Printers Using Windows Script Host File (297454)



The information in this article applies to:

  • Microsoft Windows Script Host 1.0
  • Microsoft Windows Script Host 2.0

This article was previously published under Q297454

SYMPTOMS

If you try to use the AddWindowsPrinterConnection method to add printers to Microsoft Windows 95, Microsoft Windows 98, or Microsoft Windows Millennium Edition (Me) clients, you may receive one of the following errors messages:
Error: 80070705 The printer driver is unknown.

-or-

Error: 8007070A The printer already exists.

CAUSE

This behavior can occur in Windows Script Host if either of the following conditions are true:
  • The printer driver is not installed when you use the AddWindowsPrinterConnection method in a script.

    -or-

  • Two or more installed printers use the same printer driver. The AddWindowsPrinterConnection method uses the printer driver name for the printer name.

RESOLUTION

There is no script workaround for either problem. However, you can use a custom Component Object Model (COM) or Win32 Dynamic-link Library (DLL) to resolve this problem.

Win32 DLLs allow the script to run on a local computer and reference the DLL on a remote share. This is very helpful in the case of a login script, where thousands of clients need to use the DLL but the administrator does not want to deploy the DLL. Samples of Win32 DLLs have been tested in scenarios that resulted in the error messages listed in the "Symptoms" section. For more information on these tests, see the "References" section.

STATUS

This behavior is by design.

MORE INFORMATION

To install a printer driver for Microsoft Windows 2000 or Microsoft Windows NT 4.0, the command line utility Rundll32.exe can be used.

For additional information about how to use Rundll32.exe, click the article number below to view the article in the Microsoft Knowledge Base:

164787 INFO: The Windows 95 Rundll and Rundll32 Interface

Below is a sample script using Rundll32.exe:
Dim WshShell

Set WshShell = CreateObject("WScript.Shell")
Wshell.Run "RunDLL32 <\\server\share\drvsrv,Install> "<\\server\share>", 1, True
Set WshShell = Nothing
				

Steps to Reproduce Behavior

To reproduce error 80070705, follow these steps:
  1. Replace "<\\server\share>" with a printer share on your network.
  2. Verify that the printer installed is not connected to the specified driver.
  3. Run the following sample code.
    Dim WshNetwork
    
    On Error Resume Next
    Set WshNetwork = CreateObject("WScript.Network")
    PrinterPath = "<\\server\share>"
    PrinterDriver = "Lexmark Optra S 1650"
    Set rc = WshNetwork.AddWindowsPrinterConnection(PrinterPath, PrinterDriver, PrinterPath)
    If Not rc then WScript.Echo("Printer Connection Failed!")
    End If
    					
To reproduce error 8007070A, follow these steps:
  1. Replace "<\\server\share>" with a printer share on your network.
  2. Verify that the printer installed is connected to the specified driver and the printer name is the same as the driver name.
  3. Run the following sample code.
    Dim WshNetwork
    
    On Error Resume Next
    Set WshNetwork = CreateObject("WScript.Network")
    PrinterPath = "<\\server\share>"
    PrinterDriver = "Lexmark Optra S 1650"
    Set rc = WshNetwork.AddWindowsPrinterConnection(PrinterPath, PrinterDriver, PrinterPath)
    If Not rc then WScript.Echo("Printer Connection Failed!")
    End If
    					

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

297888 SAMPLE: Drvsrv.dll Installs a Windows Printer Driver from a Print Server

300518 SAMPLE: Rename Printers via Windows Script Host

For more information on the AddWindowsPrinterConnection Method, see the following Microsoft Web page:

Modification Type:MinorLast Reviewed:3/20/2004
Keywords:kbDSWManage2003Swept kbprb KB297454