Poll: Was this script helpful?

Be advised that this is a public poll: other users can see the choice(s) you selected.

+ Post New Thread
Page 4 of 11 FirstFirst 12345678 ... LastLast
Results 46 to 60 of 165
Scripts Thread, A Printer Script in Coding and Web Development; thank you !!!!!!!!!! It works!!!...
  1. #46
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,988
    Thank Post
    287
    Thanked 273 Times in 194 Posts
    Rep Power
    116

    Re: A Printer Script

    thank you !!!!!!!!!! It works!!!

  2. #47
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    41

    Re: A Printer Script

    No probs.. glad to hear it

  3. #48
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,988
    Thank Post
    287
    Thanked 273 Times in 194 Posts
    Rep Power
    116

    Re: A Printer Script

    One last querry about this printer script im doing.
    We have lots of printers installed locally that were manually installed, so i was wondering if i have to type out
    Code:
    trComputer = "."
    		Set objWMIService = GetObject("winmgmts:" _
        			& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    			
    		Set colInstalledPrinters =  objWMIService.ExecQuery _
        			("Select * from Win32_Printer where DeviceID = 'LY1-2250'")
    
    		For Each objPrinter in colInstalledPrinters
        		objPrinter.Delete_
    for each and every printer on our network, or if there is something that can be added into the scrpit so that it will delete multiple printers instead of having lots of the above command?

    Tim

  4. #49
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,999
    Thank Post
    120
    Thanked 280 Times in 258 Posts
    Rep Power
    106

    Re: A Printer Script

    Just ommiting the where condition from the select statement should do it eg

    Code:
    ("Select * from Win32_Printer)
    This will obviously find all printers though.

  5. #50
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,988
    Thank Post
    287
    Thanked 273 Times in 194 Posts
    Rep Power
    116

    Re: A Printer Script

    ah ok, well i didnt make my self very clear, there is one local printer that needs to be kept which is called cutePDF, what i have got at the mo is

    Code:
    ' Delete Local manually installed Printers
    'Printer 1
    		strComputer = "."
    		Set objWMIService = GetObject("winmgmts:" _
        			& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    			
    		Set colInstalledPrinters =  objWMIService.ExecQuery _
        			("Select * from Win32_Printer where DeviceID = 'SR-4650'")
    
    		For Each objPrinter in colInstalledPrinters
        		objPrinter.Delete_
    
    next
    
    ' Printer 2
    		strComputer = "."
    		Set objWMIService = GetObject("winmgmts:" _
        			& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    			
    		Set colInstalledPrinters =  objWMIService.ExecQuery _
        			("Select * from Win32_Printer where DeviceID = 'LY1-2250'")
    
    		For Each objPrinter in colInstalledPrinters
        		objPrinter.Delete_
    
    next
    is there any way i can get both these printers to delete within one command instead of having two commands as shown, otherwise it will be a very long script and ive heard that, that way is a bad way of writing scripts

    Tim

  6. #51

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,710
    Thank Post
    3,246
    Thanked 1,048 Times in 970 Posts
    Rep Power
    364

    Re: A Printer Script

    In your first for loop instead of checking for the LY1-2250 and sr-4650 why not do a for loop that checks for any that aren't the cutePDF printer(s) and delete whats left over.

    ("Select * from Win32_Printer where DeviceID <> 'cutePDF'")

    For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_

    next

    That way if its not cutePDF then it deletes everything else. BTW I forgot to mention that you probably wont need the 2nd for.... loop as your first one if modified should delete all the left over ones

  7. #52
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,988
    Thank Post
    287
    Thanked 273 Times in 194 Posts
    Rep Power
    116

    Re: A Printer Script

    ahh good idea, will try that tomorrow.

  8. #53
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Re: A Printer Script

    Having had to try and figure this out the hard way (yes I know I should know but I didn't)...

    ... if you want to set the default printer for a particular room/etc.. and that printer is local then you need to find out how it's connected (eg: USB002) and then set it like this:

    Code:
    WshNetwork.SetDefaultPrinter "USB002"
    Simple isn't it... ops:

  9. #54

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,803
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: A Printer Script

    Yes, the information you need is the port name.

  10. #55
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Re: A Printer Script

    Quote Originally Posted by Geoff
    Yes, the information you need is the port name.
    .. *gritted teeth*.. and where were you an hour ago when I needed ya..

    Ah well.. learned that one.

  11. #56
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,988
    Thank Post
    287
    Thanked 273 Times in 194 Posts
    Rep Power
    116

    Re: A Printer Script

    Can some just help me to add into this script a variable for a specific user, ie, if joe bloggs wanted a certain printer? and fred smith got another printer?

    Thanks

    T

    Code:
    ' Script to add network printers to workstations and thin clients WHEN THEY ARE PART OF A SPECIFIC GROUP IN AD
    
    ' Declare variables and enumerate existing printer connections
    
    ' Setting the parameters up
    
    On error resume next
    
    	Set WshShell = WScript.CreateObject("WScript.Shell")
    	Set WshNetwork = WScript.CreateObject("WScript.Network")
    	Set wshnetwork = CreateObject("WScript.Network")
    	Set ADSysInfo = CreateObject("ADSystemInfo")
    	Set CurrentUser = GetObject("LDAP://" & ADSysInfo.Username)
    	Set oPrinters = WshNetwork.EnumPrinterConnections
    	dim Counter, PrinterPath
    	dim strConnectString, strResult
    	strGroups = LCase(CurrentUser.MemberOf)
    	strGroups = LCase(Join(CurrentUser.MemberOf))
    
    
    
    ' Sets the groups up with the member of settings in AD
    
    		Const Maths	= "cn=mathematics"
    		Const ITstaff	= "cn=information technology"
    		Const ITAdmin	= "cn=admin"
    		Const DesTech	= "cn=design and technology"
    		Const Careers	= "cn=careers"
    		Const Enterprise = "cn=enterprise"
    
    
    Dim computerName
    	computerName = LCase(WshNetwork.ComputerName)
    
    
    'WScript.Echo "computername variable: " & (computerName)
    
    
    'Deletes All Network Printers... Not manually installed
    	For i = 0 to oPrinters.Count - 1 step 2
    			On Error Resume Next
    								
    			Wshnetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true
    		
    	NEXT
    
    
    
    ' Adding Printers
    
    ' ITstaff Group
    if Instr(strGroups,ITstaff) then
    
    	wshnetwork.AddwindowsPrinterConnection "\\hades\office-ml2250"
    		
    		End If 'ITstaff
    
    
    ' Maths Group
    If Instr(strGroups,Maths) then
    
    	wshnetwork.AddwindowsPrinterConnection "\\hades\MATHS-1320"
    	wshnetwork.AddwindowsPrinterConnection "\\hades\MATHS-6980"
    		wshnetwork.setdefaultprinter "\\hades\maths-1320"
    
    		End If 'maths
    
    
    ' ITAdmin Group
    If Instr(strGroups,ITadmin) then
    	
    	wshnetwork.AddwindowsPrinterConnection "\\hades\SR-4650"
    		
    		End If 'ITadmin
    
    
    ' DesTech Group
    If Instr(strGroups,DesTech) then
    
    	wshnetwork.AddwindowsPrinterConnection "\\hades\r7-2600n"
    		
    		End If 'DesTech
    
    
    ' Careers Group
    If Instr(strGroups,Careers) then
    	
    	wshnetwork.AddwindowsPrinterConnection "\\hades\enterprise-2600n"
    	wshnetwork.AddwindowsPrinterConnection "\\careers-01\CareersPrinter"
    		wshnetwork.setdefaultprinter "\\careers-01\CareersPrinter"
    
    		End If 'Careers
    
    ' enterprise group
    If Instr(strGroups,Enterprise) then
    	
    	wshnetwork.AddwindowsPrinterConnection "\\hades\r7-2600n"
    	
    		End If 'Enterprise
    
    
    ' Adding Printers depentant on computer name
    
    Select case (Left(computername,3))
    	
    	Case "wr-"
    		wshnetwork.addwindowsprinterconnection "\\hades\wr-2200"
    			wshnetwork.setdefaultprinter "\\hades\wr-2200"
    
    End Select
    
    
    
    Select Case (computerName)
    
    	Case "lft_6169-at"
    		
    		wshnetwork.addwindowsprinterconnection "\\hades\LY1-2200"
    		wshnetwork.setdefaultprinter "\\hades\LY1-2200"
    
    End Select
    Select Case (computerName)
    
    	Case "lft_6169-at"
    		
    		wshnetwork.addwindowsprinterconnection "\\hades\LY1-2200"
    		wshnetwork.setdefaultprinter "\\hades\LY1-2200"
    
    End Select
    
    Select Case (computerName)
    
    	Case "hoy7"
    		
    		wshnetwork.addwindowsprinterconnection "\\hades\wr-2200"
    		wshnetwork.setdefaultprinter "\\hades\wr-2200"
    
    End Select

  12. #57
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,999
    Thank Post
    120
    Thanked 280 Times in 258 Posts
    Rep Power
    106

    Re: A Printer Script

    You can grab the username with:

    Code:
    Uname= wshnetwork.Username
    and use Uname as your variable.

  13. #58
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,988
    Thank Post
    287
    Thanked 273 Times in 194 Posts
    Rep Power
    116

    Re: A Printer Script

    so i would set in the header

    Code:
    uname= wshnetwork.username
    then what would i put in the working area of the script?

    T

  14. #59

    Join Date
    Sep 2006
    Location
    Essex
    Posts
    777
    Thank Post
    1
    Thanked 31 Times in 29 Posts
    Rep Power
    23

    Re: A Printer Script

    or

    Code:
    strUser = wshnetwork.UserDomain

  15. #60
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,988
    Thank Post
    287
    Thanked 273 Times in 194 Posts
    Rep Power
    116

    Re: A Printer Script

    so to map a printer for a user would it be

    if Instr(struser."joe.bloggs") then

    wshnetwork.AddwindowsPrinterConnection

SHARE:
+ Post New Thread
Page 4 of 11 FirstFirst 12345678 ... LastLast

Similar Threads

  1. logon script for printer
    By ozzy in forum Scripts
    Replies: 6
    Last Post: 22nd November 2007, 03:03 PM
  2. Printer Script
    By faza in forum Scripts
    Replies: 9
    Last Post: 14th September 2007, 08:30 AM
  3. Logon script & Printer script question.
    By Galway in forum Windows
    Replies: 3
    Last Post: 29th August 2007, 11:00 AM
  4. Add printer script not workling
    By mark in forum Windows
    Replies: 6
    Last Post: 15th September 2005, 10:07 AM
  5. Script to delete printer
    By tosca925 in forum Scripts
    Replies: 2
    Last Post: 31st August 2005, 07:45 PM

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 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
  •