+ Post New Thread
Results 1 to 9 of 9
Windows 7 Thread, printer scripts in Technical; Hi Guys We'ce recently put in around 50 windows 7 pc's into a school migrating from windows xp. I used ...
  1. #1

    Join Date
    May 2011
    Location
    Leicester
    Posts
    11
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    printer scripts

    Hi Guys

    We'ce recently put in around 50 windows 7 pc's into a school migrating from windows xp. I used to have a printer script that would execute at startup, which was simply; \\server name\printer name which worked perfectly well whether it was a logon script or you typed it in command prompt. It still works if you type it in the address bar but not in command prompt or as a logon script.

    I was wondering if anyone could provide me with an alternative?

    Cheers

  2. #2
    TheScarfedOne's Avatar
    Join Date
    Apr 2007
    Location
    Plymouth, Devon
    Posts
    1,298
    Thank Post
    619
    Thanked 162 Times in 147 Posts
    Blog Entries
    78
    Rep Power
    83
    Here is a section of the one I used before I just moved schools...

    ' WSH - Windows Logon Script
    ' Type and Target: Printers Logon Script for Workstations
    ' Location: **
    ' Compiled: August 2007
    ' Author: **


    ' Section 1: Error Handling and Variables
    ' ================================================== ==

    ' Declare variables and enumerate existing printer connections

    On Error Resume Next

    Set WshShell = WScript.CreateObject("WScript.Shell")

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

    Set oPrinters = WshNetwork.EnumPrinterConnections

    Dim computerName

    computerName = LCase(WshNetwork.ComputerName)


    ' Delete existing connections to network printers

    For i = 0 to oPrinters.Count - 1 Step 2

    On Error Resume Next

    if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then

    WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true

    else

    end if

    Next



    ' Section 2: Remove MS XPS and MS Office Image Writers
    ' ================================================== ==

    'strComputer = "."
    'Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    'Set colInstalledPrinters = objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")

    'For Each objPrinter in colInstalledPrinters
    ' IF objPrinter.Name = "Microsoft Office Document Image Writer" THEN
    ' objPrinter.Delete_
    ' ELSEIF objPrinter.Name = "Microsoft XPS Document Writer" THEN
    ' objPrinter.Delete_
    ' END IF
    'Next


    ' Section 3: Map printer connections based on Location
    ' ================================================== ==


    ' Add printer connections dependant upon location - first 6 characters of machine name

    Select Case (Left(computerName, 6))

    Case "admadm"

    WshNetwork.AddWindowsPrinterConnection "\\PrintServerNameHere\PrinterName"

    WshNetwork.SetDefaultPrinter "\\PrintServerNameHere\PrinterName"

    Case "admart"

    WshNetwork.AddWindowsPrinterConnection "\\PrintServerNameHere\PrinterName"
    WshNetwork.AddWindowsPrinterConnection "\\PrintServerNameHere\PrinterName"
    WshNetwork.AddWindowsPrinterConnection "\\PrintServerNameHere\PrinterName"

    WshNetwork.SetDefaultPrinter "\\PrintServerNameHere\PrinterName"

    End Select

  3. #3

    Join Date
    May 2011
    Location
    Leicester
    Posts
    11
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Is there a simpler method, similar to what I was using before. I'm not too hot on scripts yet?

  4. #4
    jamesreedersmith's Avatar
    Join Date
    Sep 2009
    Location
    Ruskington
    Posts
    1,158
    Thank Post
    78
    Thanked 253 Times in 227 Posts
    Rep Power
    77
    Client Side Extensions!

  5. #5

    Join Date
    May 2011
    Location
    Leicester
    Posts
    11
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Ahh but im using windows server 2003 so will that still work James?

  6. #6


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,593
    Thank Post
    228
    Thanked 856 Times in 735 Posts
    Rep Power
    296
    see no reason why not if you have 2003r2+ server you can always deploy printers via gpo. make a new gpo go to computer config (or user if you prefer) \windows settings \ deployed printers.

    You may or may not need to use rsat on a win7 pc and set point to print

    computer config \ admin templates \ printers point and print restrictions
    disable
    enable
    do not show
    do not show

    that one seems to be a bit hit and miss wether you need it or not

    or option 3

    ' Printers.vbs - sted
    Option Explicit
    Dim objNetwork

    Set objNetwork = CreateObject("WScript.Network")
    objNetwork.AddWindowsPrinterConnection "\\server\laser1mono"
    objNetwork.AddWindowsPrinterConnection "\\server\laser1col"

    objNetwork.SetDefaultPrinter "\\server\Laser1mono"

    again you may or may not need point and print setting

  7. #7
    Cache's Avatar
    Join Date
    Apr 2008
    Location
    Cumbria
    Posts
    1,215
    Thank Post
    454
    Thanked 176 Times in 173 Posts
    Blog Entries
    3
    Rep Power
    64
    Client Side Extensions will still work without a problem, you'll just need to use a Windows vista/7/server 2008 machine to configure the GPO.

  8. #8
    AlexB's Avatar
    Join Date
    Jul 2006
    Location
    Warwickshire
    Posts
    365
    Thank Post
    36
    Thanked 36 Times in 32 Posts
    Rep Power
    23
    Quote Originally Posted by svaughan View Post
    Is there a simpler method, similar to what I was using before. I'm not too hot on scripts yet?
    I know you aren't particularly looking for a script, but I thought I'd slide another one in just to show you an alternative

    This script has 2 parts, the script and the config file. The only configuration needed in the script is at the top to point to the config file and then everything in done in a much easier to understand .ini file. This was developed because GPO changes in this domain (shared domain across many schools) take around 2 hours to deploy and I wanted an easier and quicker way to change printer setups.


    printers.vbs
    Code:
    ' Script to mount printers based on computer's OU
    ' 20/09/2010 by ACB
    ' Reads printers and OUs from a printers.ini file specified in the printers.ini file
    ' printers.ini file is set by the strINIFile variable
    strINIFile = "\\<path to shared file\printers.ini"
    
    
    '***********************************************************
    ' Please use the printer name and NOT the printer share name
    '***********************************************************
    
    
    ' Default print server is read from the ini file in the [settings] section from the "server" key
    ' The computer's OU is then read from the [printers] section as a comma separated string
    ' The first entry in the printer string is used as the default printer
    ' If the OU is not found no error is returned and no additional printers are mapped
    ' There must be no spaces between printer share names in the comma separated string
    
    ' Custom printers (printers from different print servers) are read from the [custom] section
    ' The result from the [custom] section provides a comma separated string containing "print server, share name"
    ' Custom printers are currently set to be the default.
    ' The must be no space after the comma after the server name in the comma separated string
    
    ' Printers for every computer can be added in the [everyone] section
    
    ' Finally any other network printers are removed (rather than removing all network printers and reconnecting, this saves time)
    ' The variable boolRemoveOtherPrinter can be set to false to remove this functionality.
    boolRemoveOtherPrinter = true
    ' Also, there is a [nodelete] section whichs allows you to specify network printers that should not be deleted.
    
    
    
    Set objSysInfo = CreateObject("ADSystemInfo")
    strName = objSysInfo.ComputerName
    
    arrComputerName = Split(strName, ",")
    arrOU = Split(arrComputerName(1), "=")
    strComputerOU = arrOU(1)
    strPrintServer = ReadIni( strINIFile, "settings", "server")
    
    
    Set objDictionary = CreateObject("scripting.dictionary")
    
    ' ********************
    ' ********************
    ' Temp fix to remove all printers first
    'RemoveOtherPrinters
    ' ********************
    ' ********************
    
    ' *********************
    ' Read and mount printers for computer's OU
    strPrinters = ReadIni( strINIFile, "printers", strComputerOU)
    
    listPrinters = Split(strPrinters, ",")
    
    if UBound(listPrinters) >= 0 then
    	MapPrinter listPrinters(intX), true
    	For intX = 1 To UBound(listPrinters)
    		MapPrinter listPrinters(intX), false
    	Next
    end if
    ' *********************
    
    
    ' *********************
    ' Look for custom printers
    strCustomPrinter = ReadIni( strINIFile, "custom", strComputerOU)
    
    listCustomPrinters = Split(strCustomPrinter, ",")
    
    
    if UBound(listCustomPrinters) = 1 then
    	' string has correct format
    	MapPrinterCustom listCustomPrinters(1), listCustomPrinters(0), true
    end if
    ' *********************
    
    
    ' *********************
    
    ' Look for printers for everyone
    strEvPrinters = ReadIni( strINIFile, "everyone", "Printers")
    
    listEvPrinters = Split(strEvPrinters, ",")
    
    
    if UBound(listEvPrinters) >= 0 then
    	For intX = 0 To UBound(listEvPrinters)
    		MapPrinter listEvPrinters(intX), false
    	Next
    end if
    ' *********************
    
    
    ' *********************
    ' Remove other network printers
    if boolRemoveOtherPrinter then
    	RemoveOtherPrinters
    end if
    ' *********************
    
    
    ' *********
    ' Functions
    ' *********
    Function MapPrinter(strPrinter,boolDefault)
    	Set objNetwork = CreateObject("WScript.Network")
    	MapPrinterCustom strPrinter, strPrintServer, boolDefault
    
    End Function
    
    
    
    Function MapPrinterCustom(strPrinter,strServer,boolDefault)
    
    	Set objNetwork = CreateObject("WScript.Network")
    	
    	strFullPath = UCase("\\" & strServer & "\" & strPrinter)
    	'WScript.Echo "Mounting:" & strFullPath
    	objNetwork.AddWindowsPrinterConnection strFullPath
    	if boolDefault then
    		objNetwork.SetDefaultPrinter strFullPath
    	end if
    	
    	'WScript.Echo "Mounted:" & strFullPath
    	objDictionary.Add strFullPath, strPrinter
    
    End Function
    
    Function IsInList(list, value)
    
    	IsInList = false
    	For i = 0 To UBound(list)
    		if UCase(list(i)) = UCase(value) then
    			IsInList = true
    		end if
    	next
    
    End Function
    
    Function RemoveOtherPrinters()
    	Dim objPrinters, intDrive, intNetLetter
    
    	' This is the heart of the script 
    	' Here is where objPrinters enumerates the mapped drives
    	Set objNetwork = CreateObject("WScript.Network") 
    	Set objPrinters = objNetwork.EnumPrinterConnections
    	strNoDelete = ReadIni( strINIFile, "nodelete", "Printers")
    	listNoDelete = Split(strNoDelete, ",")
    
    	If objPrinters.Count <> 0 Then 
    		
    		For i = 0 to objPrinters.Count - 1 Step 2
    
    			If Left(ucase(objPrinters.Item(i+1)),2) = "\\" Then
    				'if not listNoDelete.Contains(objPrinters.Item(i+1)) then
    				if not IsInList(listNoDelete, objPrinters.Item(i+1)) then
    					if not objDictionary.Exists(UCase(objPrinters.Item(i+1))) Then
    						'WScript.Echo "Leftover: " & objPrinters.Item(i+1)
    						objNetwork.RemovePrinterConnection objPrinters.Item(i+1)
    					end if
    				end if
    			end if
    		Next
    		
    	end if
    
    End Function
    
    ' e.g. RemovePrinter "\\sba4730-ps\Mono_Tech"
    Function RemovePrinter(strPrinter)
    	Set objNetwork = WScript.CreateObject("WScript.Network") 
    	objNetwork.RemovePrinterConnection strPrinter, true, true
    End Function
    
    Function ReadIni( myFilePath, mySection, myKey )
        ' This function returns a value read from an INI file
        '
        ' Arguments:
        ' myFilePath  [string]  the (path and) file name of the INI file
        ' mySection   [string]  the section in the INI file to be searched
        ' myKey       [string]  the key whose value is to be returned
        '
        ' Returns:
        ' the [string] value for the specified key in the specified section
        '
        ' CAVEAT:     Will return a space if key exists but value is blank
        '
        ' Written by Keith Lacelle
        ' Modified by Denis St-Pierre and Rob van der Woude
    
        Const ForReading   = 1
        Const ForWriting   = 2
        Const ForAppending = 8
    
        Dim intEqualPos
        Dim objFSO, objIniFile
        Dim strFilePath, strKey, strLeftString, strLine, strSection
    
        Set objFSO = CreateObject( "Scripting.FileSystemObject" )
    
        ReadIni     = ""
        strFilePath = Trim( myFilePath )
        strSection  = Trim( mySection )
        strKey      = Trim( myKey )
    
        If objFSO.FileExists( strFilePath ) Then
            Set objIniFile = objFSO.OpenTextFile( strFilePath, ForReading, False )
            Do While objIniFile.AtEndOfStream = False
                strLine = Trim( objIniFile.ReadLine )
    
                ' Check if section is found in the current line
                If LCase( strLine ) = "[" & LCase( strSection ) & "]" Then
                    strLine = Trim( objIniFile.ReadLine )
    
                    ' Parse lines until the next section is reached
                    Do While Left( strLine, 1 ) <> "["
                        ' Find position of equal sign in the line
                        intEqualPos = InStr( 1, strLine, "=", 1 )
                        If intEqualPos > 0 Then
                            strLeftString = Trim( Left( strLine, intEqualPos - 1 ) )
                            ' Check if item is found in the current line
                            If LCase( strLeftString ) = LCase( strKey ) Then
                                ReadIni = Trim( Mid( strLine, intEqualPos + 1 ) )
                                ' In case the item exists but value is blank
                                If ReadIni = "" Then
                                    ReadIni = " "
                                End If
                                ' Abort loop when item is found
                                Exit Do
                            End If
                        End If
    
                        ' Abort if the end of the INI file is reached
                        If objIniFile.AtEndOfStream Then Exit Do
    
                        ' Continue with next line
                        strLine = Trim( objIniFile.ReadLine )
                    Loop
                Exit Do
                End If
            Loop
            objIniFile.Close
        Else
            WScript.Echo strFilePath & " doesn't exists. Exiting..."
            Wscript.Quit 1
        End If
    End Function
    
    Function DebugPopup(strMessage)
    
    	Set WshShell = CreateObject("WScript.Shell")
    
    	WshShell.Popup strMessage, , , 64 
    
    End Function

    printers.ini
    Code:
    [settings]
    server = <print server name>
    
    [printers]
    OU = defaultPrinter,nextPrinter,nextPrinter,etc...
    Digital_Studio = Mono - Studio,Colour - Studio
    Library = Mono - Library,Colour - Library
    Mobiles = Mono - Workroom,Mono - Room 6A,Colour - Room 6A
    Rm_16 = Mono - SEN,Colour - Room 6A
    Rm_17 = Mono - Music,Colour - Room 6A
    Rm_1A = Mono - Workroom,Mono - Room 6A,Colour - Room 6A
    Rm_24 = Mono - Tech,Colour - Tech
    
    [custom]
    Science = <server name/ip>,Mono Science
    
    [everyone]
    Printers = Colour - A3 - Tech
    
    [nodelete]
    Printers = \\xxxx-ps\Mono - Photocopier

  9. #9

    Join Date
    Dec 2007
    Location
    cumbria
    Posts
    182
    Thank Post
    7
    Thanked 43 Times in 39 Posts
    Rep Power
    25
    Quick and dirty way - try placing a shortcut in the all users startup folder .

SHARE:
+ Post New Thread

Similar Threads

  1. Printer Scripts
    By FN-GM in forum Scripts
    Replies: 4
    Last Post: 27th December 2007, 02:11 PM
  2. Printer Scripts
    By faza in forum Wireless Networks
    Replies: 3
    Last Post: 27th July 2007, 05:15 PM
  3. Printer scripts in GPO
    By Kyle in forum How do you do....it?
    Replies: 2
    Last Post: 25th April 2007, 07:12 AM
  4. Printer Scripts
    By Gordie in forum Windows
    Replies: 1
    Last Post: 21st February 2006, 04:35 PM
  5. printer scripts again!
    By chrbb in forum Windows
    Replies: 4
    Last Post: 10th February 2006, 12:19 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •