Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default printer - local

Status
Not open for further replies.

jbmoberly76

IS-IT--Management
May 31, 2005
1
US
I need help setting up default printers. I have used Mark D. MacLachlan's script as a template and it works great for nearly all my needs. My script connects users to network printers and sets the preferred network printer as the default. However, I have a couple of users who have local printers that they want to keep as defaults. I found a post from a couple of weeks ago that addresses this issue, but the script isn't working for me, and I'm not sure why. I would appreciate any help I can get!

Here is the portion of the script in question:
(the last section that addresses local printers is the only part that doesn't seem to work)

============================================================


WSHNetwork.AddWindowsPrinterConnection "\\DC\5P1", "5P1"
WSHNetwork.AddWindowsPrinterConnection "\\DC\5P2", "5P2"
WSHNetwork.AddWindowsPrinterConnection "\\DC\5P3", "5P3"
WSHNetwork.AddWindowsPrinterConnection "\\DC\Canon2200-PCL", "Canon 2200-PCL"
WSHNetwork.AddWindowsPrinterConnection "\\DC\Canon5000-PCL6", "Canon 5000-PCL"

WSHNetwork.SetDefaultPrinter "\\DC\5P3"

Next

'Enumerate printers and set local printer as default
'Warning: If user has more than one local printer
' then the last one detected will be default
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) <> "\\" Then
WSHNetwork.SetDefaultPrinter WSHPrinters.Item(LOOP_COUNTER +1),True,True
End If
Next

============================================================

thanks in advance for your assistance

Joe
 
Joe,

Some thought to troubleshoot this:

Code:
[red]      On Error Resume Next[/red]
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
    If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) <> "\\" Then
[red]      Wscript.Echo WSHPrinters.Item(LOOP_COUNTER +1)[/red]
      WSHNetwork.SetDefaultPrinter WSHPrinters.Item(LOOP_COUNTER +1),True,True
    End If
Next

I hope you find this post helpful.

Regards,

Mark
 
The way I handled that local printer problem was to create a security group in AD called LocalPrintUsers and append the following snippet to the login script:

Code:
' Create network object.
Set objNetwork = WScript.CreateObject("WScript.Network")

' Get username of domain user.
strUserName = objNetwork.UserName

' Get local user attributes from DC.
Set objGroup = GetObject("LDAP://" & strUserName)

' Quit script if user is member of a local printers group
For Each Member in objGroup.GetEx("memberof")
    If Member = "CN=LocalPrintUsers,OU=myou,DC=mydomain,DC=local" Then
		WScript.Quit
    End If	
Next

' Set default printer
objNetwork.SetDefaultPrinter strDefaultPrinter

Paul

Work on Windows, play on Linux.
 
A suggestion for the solution that Paul has posted,

Instead of quiting the script which would require it to be at the end at all times or you won't execute any other code, do something like this: (additions to my posted script in red)

Code:
[red]LocalPrinter = "False"[/red]

For Each GroupObj In UserObj.Groups
    Select Case GroupObj.Name
    'Check for group memberships and take needed action
    'In this example below, ADMIN and WORKERB are groups.
        Case "Admin"
            WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
        Case "WorkerB"
            WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True
            'Below is an example of how to set the default printer
            WSHNetwork.SetDefaultPrinter "\\ServerName\PrinterName"
[red]
        Case "LocalPrinter"
             LocalPrinter="True"
[/red]
    End Select
Next
[red]
If LocalPrinter = "False" Then
    [b]'printer code to execute for NON local users[/b]
Else
    [b]'printer code (may be left blank) to execute for local users[/b]
End If[/red]

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top