Jump to content

Recommended Posts

Posted (edited)

Hi all,

 

I've been given a VBScript to amend to resolve a printer issue we have on site..

 

I'm missing something that's causing an error..

 

I believe its related to the "" on the printer remove lines.. Can anyone advise further?

 

I know it looks odd, but i need to remove an old printer setup and then refresh it, as such..

 

The script is:

 

' SET DEFAULT PRINTER SCRIPT

ON ERROR RESUME NEXT

dim oNetwork

Set oNetwork = WScript.CreateObject("WScript.Network")

 

' INSTALL PHOTOCOPIER AS NETWORK PRINTER

ONetwork.RemovePrinterConnection "\\bobs-server\ICTSUITE COPIER COLOUR"

ONetwork.RemovePrinterConnection "\\bobs-server\ICTCOPIER BLACK & WHITE"

ONetwork.AddWindowsPrinterConnection "\\bobs-server\ICTSUITE COPIER COLOUR"

ONetwork.AddWindowsPrinterConnection "\\bobs-server\ICTCOPIER BLACK & WHITE"

 

 

Select Case ucase(oNetwork.ComputerName)

CASE "SONY-VAIO"

ONetwork.SetDefaultPrinter "HP5940"

CASE ELSE

ONetwork.SetDefaultPrinter "\\bobs-SERVER\ICTCOPIER BLACK & WHITE"

 

 

End Select

 

WScript.Quit

' End of Script

 

 

Any feedback would be really appreciated as this is causing no end of bother at the moment..

 

Unfortunately, we are extremely limited on testing, so hopefully a correct script will do the job once corrected..

 

Thanks in advance all,

 

D..

Edited by Dwelb
syntax
Posted
Just to confirm was the error line correct in the actual script as if it wasn't and one of the printers you want to remove was not on the computer then the script would error out.
Posted
Just to confirm was the error line correct in the actual script as if it wasn't and one of the printers you want to remove was not on the computer then the script would error out.

 

Hi, the error message is below:

bob.png

bob.png

Posted
Assuming your vbs script itself is laid out exactly how it is in the original post then this would confirm that the issue is with the on error line. If it isn't can you provide a screen grab with the vbs file open in notepad so we can see exactly how it looks without having to worry about transcription errors.
  • Thanks 1
Posted
Assuming your vbs script itself is laid out exactly how it is in the original post then this would confirm that the issue is with the on error line. If it isn't can you provide a screen grab with the vbs file open in notepad so we can see exactly how it looks without having to worry about transcription errors.

 

Hi, I've attached what was working and what i require to work..

I'm seeing other info out there mentioning that we do not need the ""'s around the remove line.

1. Can anyone advise if this is the case?

2. If the script error-ed out, would it continue because of the "ON ERROR RESUME NEXT" line?

bobs script.JPG

Thanks in advance and sorry for the delayed replies.. :rolleyes:

Posted

Odd.

I've just tried to run your code (copied from the first post) and if I put in my server & printer details it works fine. Even with error handling turned off it runs through without kicking up any messages and with the expected results.

 

If I take the quotation marks out from around the printer path then I get Syntax errors - so you definitely need them in.

 

I don't see any need for the "dim oNetwork" line at the start, but otherwise all looks good.

Posted
Odd.

I've just tried to run your code (copied from the first post) and if I put in my server & printer details it works fine. Even with error handling turned off it runs through without kicking up any messages and with the expected results.

 

If I take the quotation marks out from around the printer path then I get Syntax errors - so you definitely need them in.

 

I don't see any need for the "dim oNetwork" line at the start, but otherwise all looks good.

 

Hi Rob, Thank you for testing and confirming all is well.. Much appreciated..:D

 

I can only further test tomorrow afternoon now due to user availability..

 

Someone else has written this script and entered the "dim oNetwork".. Can you advise what this entails? Tia.. :eyebrows:

Posted
Someone else has written this script and entered the "dim oNetwork".. Can you advise what this entails? Tia.. :eyebrows:

As far as my understanding of VBS goes, DIM is used to enumerate variables prior to use. So, I guess it makes sense it being there. But I can't recall seeing it used for WScript variables before.

I just stuck a single quote in front to "comment out" the line, but I don't think it being there, or not, makes any difference.

  • Thanks 1
Posted
Hi Rob, Thank you for testing and confirming all is well.. Much appreciated..:D

 

I can only further test tomorrow afternoon now due to user availability..

 

Someone else has written this script and entered the "dim oNetwork".. Can you advise what this entails? Tia.. :eyebrows:

 

Hi all, I've been on this all afternoon and have to give up today due to lack of free staff..

 

If I manually run the VBScript on a user profile/desktop, everything works a treat! All printers disappear, two re-appear and on is set as default!

 

If it is invoked via logon.bat, it fails to complete. No error message or completion line in the paused output either.

 

I've dropped this on three different users/machines and it still acts the same..

 

More testing tomorrow..

 

Any additional ideas guys/girls??:confused::sick:

Posted
Are you sure the script is actually being started from the logon.bat correctly and it is not the command in the bat file that is failing and not the vbs script itself?
Posted
If it is invoked via logon.bat, it fails to complete.

Perhaps it might be worth trying Microsoft's printer VBS scripts which are included with Windows? e.g.

 

:: Delete printer
cscript "%SystemRoot%\System32\Printing_Admin_Scripts\en-US\Prnmngr.vbs" -d -p "ICTSUITE COPIER COLOUR"
cscript "%SystemRoot%\System32\Printing_Admin_Scripts\en-US\Prnmngr.vbs" -d -p "ICTCOPIER BLACK & WHITE"

:: Add printer
cscript "%SystemRoot%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -a -p "ICTSUITE COPIER COLOUR" -m "HP Universal Printing PCL 6" -r " IP_192.168.0.100"
cscript "%SystemRoot%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -a -p "ICTCOPIER BLACK & WHITE" -m "HP Universal Printing PCL 6" -r " IP_192.168.0.101"

etc.

 

More info: https://technet.microsoft.com/en-us/library/cc725868 & http://woshub.com/manage-printers-and-drivers-from-the-command-line-in-windows-8

 

Have you considered deleting/adding the printers via Group Policy Preferences? It's much easier. :)

Posted
If it is invoked via logon.bat, it fails to complete.

If you're using a login batch file, why not use con2prt (or something similar) straight from the batch file? I used it in my last place and never had any problems with it.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...