Link to home
Start Free TrialLog in
Avatar of t3ngu
t3ngu

asked on

Need Help With Error Code 8007007B on VB Script

I have a script residing on a centralized share. The end user's PCs have a shortcut at startup that points to this script. Every time someone logs onto the computer it runs the script and maps the listed network printers. Intermittently they get an 8007007B error. It doesn't happen all the time and it no specific order, the error seems to be generating at random. The error happens on several computers with different users including people with admin rights on the domain. I've read allot of post and tried different solutions but they all generate a different error. All the systems that run script via shortcut are XP Pro machines. The script resides on a share on a Windows 2003 print server.

This is my script:

Dim net
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\ford\blue4100"
net.AddWindowsPrinterConnection "\\ford\Royal1RX"
net.AddWindowsPrinterConnection "\\ford\Royal2"
net.AddWindowsPrinterConnection "\\ford\Green1RX"
net.AddWindowsPrinterConnection "\\ford\Green2"
net.AddWindowsPrinterConnection "\\ford\Mid1"
net.AddWindowsPrinterConnection "\\ford\Mid2RX"

This is the error:
Script:   \\ford\printmap\pmap.vbs
Line:     9
Char:    1
Error:    the filename, directory name, or volume label syntax is incorrect.
Code:    8007007B
Source: (null)
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, if this is only intermittent, then you may have connectivity issues while trying to connect to printers. Perhaps some are offsite?

Try this code, which will attempt to connect to the printer up to 10 ten times, and sleep for 2 seconds on every failed attempt before trying again.

Regards,

Rob.
MapPrinter "\\ford\blue4100"
MapPrinter "\\ford\Royal1RX"
MapPrinter "\\ford\Royal2"
MapPrinter "\\ford\Green1RX"
MapPrinter "\\ford\Green2"
MapPrinter "\\ford\Mid1"
MapPrinter "\\ford\Mid2RX"
 
Sub MapPrinter(strPrinter)
    On Error Resume Next
    Set objNetwork = CreateObject("WScript.Network")
    boolConnected = False
    intAttempts = 1
    While boolConnected = False And intAttempts <= 10
        Err.Clear
        objNetwork.AddWindowsPrinterConnection strPrinter
        If Err.Number <> 0 Then
            intAttempts = intAttempts + 1
            WScript.Sleep 2000
        Else
            boolConnected = True
        End If
    Wend
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of t3ngu
t3ngu

ASKER

So far this solved my problem!! but only time will tell :) THANKS!!!
Avatar of t3ngu

ASKER

One more thing... How can I set a default printer with this script? I used to use:
net.SetDefaultPrinter \\serverName\shareName
 
SetDefaultPrinter is correct, but again, we'll make it try a few times....

Regards,

Rob.
MapPrinter "\\ford\blue4100"
MapPrinter "\\ford\Royal1RX"
MapPrinter "\\ford\Royal2"
MapPrinter "\\ford\Green1RX"
MapPrinter "\\ford\Green2"
MapPrinter "\\ford\Mid1"
MapPrinter "\\ford\Mid2RX"
 
SetDefaultPrinter "\\ford\Green2"
 
Sub MapPrinter(strPrinter)
    On Error Resume Next
    Set objNetwork = CreateObject("WScript.Network")
    boolConnected = False
    intAttempts = 1
    While boolConnected = False And intAttempts <= 10
        Err.Clear
        objNetwork.AddWindowsPrinterConnection strPrinter
        If Err.Number <> 0 Then
            intAttempts = intAttempts + 1
            WScript.Sleep 2000
        Else
            boolConnected = True
        End If
    Wend
    Err.Clear
    On Error GoTo 0
End Sub
 
Sub SetDefaultPrinter(strPrinter)
    On Error Resume Next
    Set objNetwork = CreateObject("WScript.Network")
    boolConnected = False
    intAttempts = 1
    While boolConnected = False And intAttempts <= 10
        Err.Clear
        objNetwork.SetDefaultPrinter strPrinter
        If Err.Number <> 0 Then
            intAttempts = intAttempts + 1
            WScript.Sleep 2000
        Else
            boolConnected = True
        End If
    Wend
    Err.Clear
    On Error GoTo 0
End Sub

Open in new window