Learn how to a build a cloud-first strategyRegister Now

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

VB Script Printer Issue

I have a logon script that's been running fine for years.  Recently I updated it with a new function and it has caused another (seemingly unrelated) portion of the script to break.  The broken lines are as follows:

Dim objNet
Set objNet = WScript.CreateObject("WScript.Network")
objNet.AddWindowsPrinterConnection "\\fileserver\Kyocera1"

I've tested that on one server which gives me the error: "The printer name is invalid (80070709)" (which is not true)
On the problem server I get this error: "The filename, directory name, or volume label syntax is incorrect. (8007007B)"

Any ideas?
0
netsmithcentral
Asked:
netsmithcentral
  • 9
  • 6
  • 4
1 Solution
 
merowingerCommented:
look at the sharename of the printer if it is the same like in the script!
Take a look if the printer is shared
0
 
netsmithcentralAuthor Commented:
Yes, the printer share matches up, and yes, the printer is shared.  This script has been working without fail for years.  It only recently started having problems.
0
 
merowingerCommented:
it could be that another line in your script causes problem...it must not be the line the printer is mapped!

And look at this solution:
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/XP/Q_22131828.html
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
netsmithcentralAuthor Commented:
I'm getting another error on the actual workstations.  Its

800706BE - The remote procedure call failed

Here's a complete copy of my code as it currently is:

Option Explicit

On Error Resume Next

'Uncomment to Enable Error Checking
Dim dbg: dbg = False
If UCase(objNetwork.UserName) = "MKOSBIE"  Or UCase(objNetwork.UserName) = "ADMINISTRATOR" Then
      On Error Goto 0
      dbg = True
End If

'Declare Variables
Dim objNetwork, objShell, objFSO, objPrinters
Dim locName
Dim regPath, DataSource, InitialCatalog, PassWord, UserID

'Make the Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")            'File System Object (Add/Remove/Query Files)
Set objNetwork = WScript.CreateObject("Wscript.Network")      'Network Object (Get Data About this Computer)
Set objShell = WScript.CreateObject("WScript.Shell")            'Shell Object (Runs other commands/Programs)

'Find this computer
locName = UCase(Left(objNetwork.ComputerName, 3))

'Set information about this computer
regPath = "HKCU\Software\VB and VBA Program Settings\Financial Management Suite\DataBase\"

'All Stores Script, NON TERMINAL LOGON
If UCase(objNetwork.ComputerName) <> "IDLERS01" Then
      objNetwork.MapNetworkDrive "P:", "\\idlers01\public_share"

      'Delete the old Whirlwind Desktop Shortcut
      If objFSO.FileExists(objShell.SpecialFolders("Desktop") & "\StoreManager by WhirlWind.lnk") Then
            objFSO.GetFile(objShell.SpecialFolders("Desktop") & "\StoreManager by WhirlWind.lnk").Delete
      End If

      'Automatically Generate Shortcuts to All Universal Folders
      'mkUnivFldr objShell.SpecialFolders("Desktop"), "\\idlers01\universal_folders", objFSO
      If dbg Then WScript.Echo("End Universal Routine")
End If

'Automatically set the SQL Server, Username/Password
'DataSource = objShell.RegRead(regPath & "DataSource")
'      If Err <> 0 Then objShell.RegWrite regPath & "DataSource", "idlers01", "REG_SZ" End If
'      If DataSource <> "idlers01" Then objShell.RegWrite regPath & "DataSource", "idlers01", "REG_SZ" End If
'InitialCatalog = objShell.RegRead(regPath & "InitialCatalog")
'      If Err <> 0 Then objShell.RegWrite regPath & "InitialCatalog", "WhirlwindSQL", "REG_SZ" End If
'      If InitialCatalog <> "Whirlwind" Then objShell.RegWrite regPath & "InitialCatalog", "WhirlwindSQL", "REG_SZ" End If
'PassWord = objShell.RegRead(regPath & "PassWord")
'      If Err <> 0 Then objShell.RegWrite regPath & "PassWord", "Whirl04", "REG_SZ" End If
'      If PassWord <> "Whirl04" Then objShell.RegWrite regPath & "PassWord", "Whirl04", "REG_SZ" End If
'UserID = objShell.RegRead(regPath & "UserID")
'      If Err <> 0 Then objShell.RegWrite regPath & "UserID", "sa", "REG_SZ" End If
'      If UserID <> "sa" Then objShell.RegWrite regPath & "UserID", "sa", "REG_SZ" End If

'Paso Script
If locName = "PAS" Or dbg Then
      objNetwork.MapNetworkDrive "W:", "\\idlers01\whirlwind"

      objNetwork.AddWindowsPrinterConnection "\\fileserver\Kyocera1"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Kyocera2"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Kyocera3"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Kyocera4"
      objNetwork.AddWindowsPrinterConnection "\\paso2\invoices"
      objNetwork.AddWindowsPrinterConnection "\\paso19\Devney"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Canon_Atas"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Canon_SLO"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Canon3380i"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Canon2220n"

      'Create the New Whirlwind Desktop Shortcut
      If Not objFSO.FileExists(objShell.SpecialFolders("Desktop") & "\StoreManager by WhirlWind.lnk") Then
            objFSO.CopyFile "W:\StoreManager by WhirlWind.lnk", objShell.SpecialFolders("Desktop") & "\"
      End If
End If

'Atascadero Script
If locName = "ATA" Then
      'Add Local Printers
      objNetwork.AddWindowsPrinterConnection "\\fileserver\1300n"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\salesfloor"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\HP3500"
      objNetwork.AddWindowsPrinterConnection "\\atas15\PartsOrders"
      objNetwork.AddWindowsPrinterConnection "\\atas9\ServiceOrders"
      objNetwork.AddWindowsPrinterConnection "\\atas12\salesfloor"
      objNetwork.AddWindowsPrinterConnection "\\atas11\BrotherF"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Canon_Atas"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Canon_SLO"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Canon3380i"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Canon2220n"
      
      'Copy Storewide Favorites
      objFSO.CopyFolder "P:\Atascadero Favorites", objShell.SpecialFolders("Favorites")

      'Create the New Whirlwind Desktop Shortcut
      If Not objFSO.FileExists(objShell.SpecialFolders("Desktop") & "\StoreManager by WhirlWind.rdp") Then
            objFSO.CopyFile "\\idlers01\whirlwind\StoreManager by WhirlWind.rdp", objShell.SpecialFolders("Desktop")
      End If
End If

'SLO Script
If locName = "SLO" Then
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Canon_SLO"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Canon_Atas"
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Canon3380i"
      objNetwork.AddWindowsPrinterConnection "\\slo8\HPDeskJe"
      objNetwork.AddWindowsPrinterConnection "\\slo5\HP895"

      'Create the New Whirlwind Desktop Shortcut
      If Not objFSO.FileExists(objShell.SpecialFolders("Desktop") & "\StoreManager by WhirlWind.rdp") Then
            objFSO.CopyFile "\\idlers01\whirlwind\StoreManager by WhirlWind.rdp", objShell.SpecialFolders("Desktop")
      End If
End If

'Terminal Services Script
If UCase(objNetwork.ComputerName) = "IDLERS01" Then
      objNetwork.MapNetworkDrive "P:", "\\idlers01\public_share"
End If

'Universal Folder Recursive Function
Sub mkUnivFldr(curLocPath, curRemPath, FSO)
      Dim curRemFolder
      Dim remFolder, remSubFolder
      Dim sPath
      Dim PDF, search
      Dim shortcut

      Set curRemFolder = FSO.GetFolder(curRemPath)
            

      For Each remFolder In curRemFolder.SubFolders
            sPath = curLocPath & "\" & remFolder.Name

            If Not objFSO.FolderExists(sPath) Then
                  FSO.CreateFolder(sPath)
            Else
                  Dim dFolder
                  Set dFolder = FSO.GetFolder(sPath)

                  dFolder.Delete True
                  Set dFolder = Nothing

                  FSO.CreateFolder(sPath)
            End If

            Set search = remFolder.Files

            For Each PDF In search
                  Set shortcut = objShell.CreateShortcut(sPath & "\" & Left(PDF.Name, Len(PDF.Name)-4) & ".lnk")
                  shortcut.TargetPath = PDF.Path
                  shortcut.IconLocation = "%SystemRoot%\system32\SHELL32.dll,20"

                  shortcut.Save

                  Set shortcut = Nothing
            Next

            Set search = Nothing

            mkUnivFldr curLocPath & "\" & remFolder.Name, curRemPath & "\" & remFolder.Name, FSO
      Next

      Set curRemFolder = Nothing
End Sub

'Release the Objects
Set objNetwork = Nothing
Set objShell = Nothing
Set objFSO = Nothing
Set objPrinters = Nothing
0
 
netsmithcentralAuthor Commented:
FYI, the line that is failing is line 60:


'Paso Script
If locName = "PAS" Or dbg Then
      objNetwork.MapNetworkDrive "W:", "\\idlers01\whirlwind"

      objNetwork.AddWindowsPrinterConnection "\\fileserver\Kyocera1" 'Line 60
0
 
merowingerCommented:
i would comment out little steps in this script for better locating the problem!
RPC could be anything
0
 
merowingerCommented:
ah k :)
0
 
merowingerCommented:
whats this? Right Syntax?

Dim dbg: dbg = False

Note: delete "On Error Resume Next" until the script is runing without problems
0
 
netsmithcentralAuthor Commented:
In VBScript a colon is a line terminator.  It allows you to put multiple commands on the same line.  In essence:

Dim dbg: dbg = False

Is the same as

Dim dbg
dbg = False


You'll note that I have these lines in my script:

'Uncomment to Enable Error Checking
Dim dbg: dbg = False
If UCase(objNetwork.UserName) = "ADMINISTRATOR" Then
      On Error Goto 0
      dbg = True
End If


This enables "debug mode" for the administrator user, but NOT for normal users (wouldn't want them seeing error messages throughout the day).

Any other ideas?
0
 
merowingerCommented:
have u deleted On Error Resume Next?
I think the main error is caused from another one which is not displayed! with on error resume next
0
 
netsmithcentralAuthor Commented:
Alright, I went ahead and updated my error handling code so that anyone who is a member of the "Logon Script Debuggers" group has it disabled.  Here's the beginning of my code and an explanation of why it works:


Option Explicit

On Error Resume Next

'Enable Debugging
Const DebugEnabled = True

'Declare Variables
Dim objNetwork, objShell, objFSO, objUser
Dim locName
Dim regPath, DataSource, InitialCatalog, PassWord, UserID
Dim dbg, grp

'Make the Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")            'File System Object (Add/Remove/Query Files)
Set objNetwork = WScript.CreateObject("Wscript.Network")      'Network Object (Get Data About this Computer)
Set objShell = WScript.CreateObject("WScript.Shell")            'Shell Object (Runs other commands/Programs)
Set objUser = GetObject("WinNT://idlers.local/" & objNetwork.UserName & ", user")      'User object

'Disable Error checking for administrators
dbg = False
For Each grp In objUser.Groups
      If grp.Name = "Logon Script Debuggers" And DebugEnabled Then
            WScript.Echo("Logon Script Debugging is enabled.")
            On Error Goto 0
            dbg = True
      
            Exit For
      End If
Next



First I disabled error checking ("On Error Resume Next").  THEN I reeneable it ("On Error Goto 0") for members of the "Logon Script Debuggers" group.  That means by the time I exit the for loop, I have error checking on.

This is roughly equivalent to:

On Error Resume Next
On Error Goto 0


So unless one of those statements is having the error (which is unlikely), that's not the root cause.

FYI, against my better judgment I did disable that line for one test.  The error still occurred at the same point.
0
 
RobSampsonCommented:
You can try waiting for a few seconds at the MapNetworkDrive, or check if it's mapped before hand:
Set objFSO = CreateObject("Scripting.FileSystemObject")
If locName = "PAS" Or dbg Then
      If objFSO.DriveExists("W:") = False Then
          objNetwork.MapNetworkDrive "W:", "\\idlers01\whirlwind"
          WScript.Sleep 2000 ' Wait 2 seconds
     End If
      objNetwork.AddWindowsPrinterConnection "\\fileserver\Kyocera1"
     ' etc, etc
End If

Regards,

Rob.
0
 
netsmithcentralAuthor Commented:
Rob, I tried both suggestions.  Still getting the same error in the same place.
0
 
RobSampsonCommented:
In your complete code in the fourth post on this question, you have this section:
'Uncomment to Enable Error Checking
Dim dbg: dbg = False
If UCase(objNetwork.UserName) = "MKOSBIE"  Or UCase(objNetwork.UserName) = "ADMINISTRATOR" Then
      On Error Goto 0
      dbg = True
End If

above the part where objNetwork is defined and set as a WScript.Network object, but that shouldn't matter for the particular error in question.....
Just one thing.....can you try
Set objNetwork = CreateObject("WScript.Network")
instead of:
Set objNetwork = WScript.CreateObject("Wscript.Network")

I tend to use the CreateObject method, rather than the WScript.CreateObject method. The methods are treated differently, but I personally find CreateObject more robust.  There's a very small bit of info on that here:
http://www.microsoft.com/technet/scriptcenter/resources/begin/ss0406.mspx

Regards,

Rob.
0
 
netsmithcentralAuthor Commented:
I noticed the error in the full code version of my post actually.  That's why I have the updated code to check if the user is a member of the "Logon Script Debuggers" group.  That is AFTER I instantiate the object.

I did go ahead and change to use the VBScript CreateObject method as per your recommendations.  No luck so far.
0
 
RobSampsonCommented:
So are we still getting the same "printer name is invalid error"?

Have you tried renaming the Share name of that printer, and mapping to it then?

Rob.
0
 
netsmithcentralAuthor Commented:
Yes, I'm still getting weird errors.  It's "printer name is invalid" on some computers.  It's "permission denied" on some.  There's at least one other error I cannot remember off the top of my head.  I've remade the shares (and every other trick I know) to no avail!
0
 
RobSampsonCommented:
It really does look like the printer either doesn't exist, or cannot be contacted at certain points in time, meaning it thinks it doesn't exist.

Here's a trouble-shooting step, but I'm sure you've been through this already:
http://www.computerperformance.co.uk/Logon/code/code_80070709.htm

Maybe the printer connectivity is dodgy.  Try running a ping test on the printers IP Port for a while.

Also, has there been any change in environment, other than the script? Like client OS version, service packs, server OS version?

Regards,

Rob.
0
 
netsmithcentralAuthor Commented:
Ended up replacing the printer, but here's some points for all the help you provided.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now