Announcement

Collapse
No announcement yet.

Cannot set default printer via .vbs script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot set default printer via .vbs script

    I am using a VBS script to set the default printer in our Library (XP clients only):

    It came courtesy of Guy Thomas:

    Code:
    ' SetDefaultPrinter.vbs - Windows logon script example
    ' PrintersDefault.vbs - Set the default printer
    ' VBScript - to map a network printer
    ' Author Guy Thomas http://computerperformance.co.uk/
    ' Version 1.4 - April 24th 2010
    ' ----------------------------------------------------' 
    Option Explicit
    Dim objNetwork, strUNCPrinter
    strUNCPrinter = "\\PRINTSERVER1\Ricoh Laser"
    Set objNetwork = CreateObject("WScript.Network") 
    objNetwork.AddWindowsPrinterConnection strUNCPrinter
    
    ' Here is where we set the default printer to strUNCPrinter
    objNetwork.SetDefaultPrinter strUNCPrinter
    WScript.Echo "Check the Printers folder for : " & strUNCPrinter
    
    WScript.Quit
    
    ' End of Guy's Windows logon example VBScript.
    This works well except that the computers have SMART Notebook installed and the SMART Notebook Printer keeps re-appearing and stops the script from setting the default printer, I presume because it comes later in the log in process. I delete it and it comes back. Can anyone provide pointers to stop this?

    Thanks for you time - it's much appreciated.
    Last edited by biggles77; 10th May 2011, 04:49. Reason: Wrap script in CODE tag

  • #2
    Re: Cannot set default printer via .vbs script

    Originally posted by pksupport View Post
    I am using a VBS script to set the default printer in our Library (XP clients only):

    It came courtesy of Guy Thomas:
    Code:
    ...
    This works well except that the computers have SMART Notebook installed and the SMART Notebook Printer keeps re-appearing and stops the script from setting the default printer, I presume because it comes later in the log in process. I delete it and it comes back. Can anyone provide pointers to stop this?

    Thanks for you time - it's much appreciated.
    I don't know what is the behaviour of this software, mostlikely that its printer is re-installing at every logon and is just using the settings of the 'add printer wizard' for it - therefore try this script see if it makes a different.
    Code:
    ' SetDefaultPrinter.vbs - Windows logon script example
    ' PrintersDefault.vbs - Set the default printer
    ' VBScript - to map a network printer
    ' Author Guy Thomas http://computerperformance.co.uk/
    ' Version 1.4 - April 24th 2010
    ' ----------------------------------------------------' 
    Option Explicit
    Dim WshShell
    Dim objNetwork, strUNCPrinter
    
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.RegWrite "HKCU\Printers\Settings\Wizard\Set As Default", 0, "REG_DWORD"
    
    strUNCPrinter = "\\PRINTSERVER1\Ricoh Laser"
    Set objNetwork = CreateObject("WScript.Network") 
    objNetwork.AddWindowsPrinterConnection strUNCPrinter
    
    ' Here is where we set the default printer to strUNCPrinter
    objNetwork.SetDefaultPrinter strUNCPrinter
    WScript.Echo "Check the Printers folder for : " & strUNCPrinter
    
    WScript.Quit
    
    ' End of Guy's Windows logon example VBScript.
    /Rems
    Last edited by Rems; 10th May 2011, 13:59.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Cannot set default printer via .vbs script

      Thanks so much for this - it seemed to be working; however I have another slight hitch. I had to create 2 print queues for this printer: Library_greyscale (which I want to be set as the default) and Library_colour, which I want to be available, but not default. Is there a way to do this in one script, or should I run another? I have tried a few things without success. Once again, thanks for this help - it's a problem the Librarian would certainly like fixed.

      Comment


      • #4
        Re: Cannot set default printer via .vbs script

        try adding following:

        Originally posted by original
        strUNCPrinter = "\\PRINTSERVER1\Ricoh Laser"
        Set objNetwork = CreateObject("WScript.Network")
        objNetwork.AddWindowsPrinterConnection strUNCPrinter
        so add this instead:

        strUNCPrinter = \\PRINTSERVER1\Ricoh Laser
        strUNCPrinter2 = \\PrintSErver1\Ricoh_Color
        Set objNetwork = CreateObject("WScript.Network")
        objNetwork.AddWindowsPrinterConnection strUNCPrinter
        objNetwork.AddWindowsPrinterConnection strUNCPrinter2


        no need to concern with the adding default, that's still there..
        Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

        Comment


        • #5
          Re: Cannot set default printer via .vbs script

          Originally posted by tehcamel View Post
          try adding following:



          so add this instead:

          strUNCPrinter = \\PRINTSERVER1\Ricoh Laser
          strUNCPrinter2 = \\PrintSErver1\Ricoh_Color
          Set objNetwork = CreateObject("WScript.Network")
          objNetwork.AddWindowsPrinterConnection strUNCPrinter
          objNetwork.AddWindowsPrinterConnection strUNCPrinter2


          no need to concern with the adding default, that's still there..
          Unfortunately, this doesn't work. The script won't run, gives a compiling error. I can however run 2 scripts, one for colour, one for greyscale; and it works. Also I couldn't get this to run:

          Code:
          Set WshShell = WScript.CreateObject("WScript.Shell")
          WshShell.RegWrite "HKCU\Printers\Settings\Wizard\Set As Default", 0, "REG_DWORD"
          Same problem. I did try to test carefully. I'd love to hear from anyone who regularly adds 2 printer queues at login with a vbs script. Would the DWORD script work better as a .bat (regedit) file?

          Comment


          • #6
            Re: Cannot set default printer via .vbs script

            Originally posted by pksupport View Post
            add this instead:

            strUNCPrinter = \\PRINTSERVER1\Ricoh Laser
            strUNCPrinter2 = \\PrintSErver1\Ricoh_Color
            Set objNetwork = CreateObject("WScript.Network")
            objNetwork.AddWindowsPrinterConnection strUNCPrinter
            objNetwork.AddWindowsPrinterConnection strUNCPrinter2
            Unfortunately, this doesn't work.

            The script won't run, gives a compiling error.
            both strings "\\PRINTSERVER1\Ricoh Laser" and "\\PrintSErver1\Ricoh_Color" should be between quotes.


            Originally posted by pksupport View Post
            Also I couldn't get this to run:

            Code:
            Set WshShell = WScript.CreateObject("WScript.Shell")
            WshShell.RegWrite "HKCU\Printers\Settings\Wizard\Set As Default", 0, "REG_DWORD"
            Same problem. I did try to test carefully.
            What you mean by 'same problem'? you posted earlier that 'it seemed to be working' with this addition to the script. The code part is working fine here.

            /Rems

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Cannot set default printer via .vbs script

              Sorry Rems! I am tunnelling three deep through a proxy - it's really hard to test this stuff. I copied again carefully, and the DWORD seems to go through; I still had a compiling error : Line 15/Char 1- Undefined Variable "strUNCPrinter2"

              So I looked at Guy's site on multiple printers and saw the missing variable - thanks again for your patience and help on this - much appreciated.
              Last edited by pksupport; 17th May 2011, 05:18. Reason: Found my mistake

              Comment


              • #8
                Re: Cannot set default printer via .vbs script

                Originally posted by pksupport View Post
                Sorry Rems! I am tunnelling three deep through a proxy - it's really hard to test this stuff. I copied again carefully, and the DWORD seems to go through; I still had a compiling error : Line 15/Char 1- Undefined Variable "strUNCPrinter2"

                So I looked at Guy's site on multiple printers and saw the missing variable - thanks again for your patience and help on this - much appreciated.
                Glad you got it sorted.

                Because your script is starting with Option Explicit it forces explicit declaration of all variables used in the script. This statement is optional.


                /Rems

                This posting is provided "AS IS" with no warranties, and confers no rights.

                __________________

                ** Remember to give credit where credit's due **
                and leave Reputation Points for meaningful posts

                Comment

                Working...
                X