We are experiencing what seems to be a fairly common issue with printer vbscripts; however we have not found a solution. The error we receive is "The filename, directory name or volume syntax is incorrect". This error does not occur on specific computers and is random. For instance it may occur on Computer01 one day but Computer02 the next, both Computer01 and Computer02 have the exact same vbscript and image. The vbscript may produce an error on Computer01, but at the same time work correctly on Computer02. We are running Windows XP Professional and are on a 2003 server environment for our print server. All authenticated users have rights to see and add the printers from our print server. We have tried the following troubleshooting steps and / or solutions:
First we naturally thought there may be an issue with the vbscript so we tried different vbscripts and even a batch file. What the second vbscript and the batch file proved is it can add one of the printers but not the other. One day it would allow Printer1to map fine but not Printer2, then the second day it was just the opposite.
Dim netPrinter, UNCpath
UNCpath = "\\server\Printer1"
Set netPrinter = CreateObject("WScript.Network")
Dim objNetwork, strUNCPrinter
strUNCPrinter = "\\server\Printer2"
Set objNetwork = CreateObject("WScript.Network")
' Here is where we set the default printer to strUNCPrinter
'On error keep going
ON ERROR RESUME NEXT
'Define the variables
Dim objShell, wshNet
Set wshNet = CreateObject("WScript.Network")
set objShell = WScript.CreateObject("WScript.Shell")
'Stop Printer Spooler
objShell.run "net stop Spooler",0,True
'Wait to 4 seconds continue the script
'Start Printer Spooler
objShell.run "net start Spooler",0,True
'Wait to 10 seconds continue the script
'Add the specified network printer
wshNet.AddWindowsPrinterConnection "\\Server\Printer1", "HP LaserJet 4350 PCL 6"
wshNet.AddWindowsPrinterConnection "\\Server\Printer2", "HP LaserJet 4350 PCL 6"
Third Script (Batch file as a test)
Second we thought it may be an issue related with our network access controller and the printers being incorrectly moved to the wrong vlan. However the scripts are not mapping directly to the printers they are mapping the shares from the print server. On a PC that is having the error we can reach / ping both printers and the server using the host name and FQDN, therefore that told us it was not a networking issue.
Our third thought was a driver issue. However we removed all of the drivers and ran the script and still got the same error. The computers automatically pull the drivers from the print server; therefore our thought process is it was trying to replace the driver when the script ran. For instance user01 logs in and then user02 comes and logs in and it would try to replace the current drive. However it seems that the problem would be on every computer if this was the case.
Then our fourth thought was to restart the print spooler (which is why we added that code in the second script). This sometimes will fix the issue but not always.
Finally we have come to the conclusion that this only seems to happen on computers that have had a large number of users logging into it. So we tried deleting all of the user profiles and seeing if the script would run then. We could delete all but two user profiles on the system. The two that we couldn’t delete had files under the user profile that we locked. From here we are thinking that the script isn’t letting the printer map because another user has a thread running under a process, or a locked file that is still making use of the printer. One solution we thought of was to delete the user profiles upon logout, however if files under it are locked then the user profile cannot be deleted.