Set Default Printer via VBScript

If you don't want to use Group Policy for setting default printers for your users you can use VBScript.

I know that the preferred method of setting the printer is via GPO, but this gives you an alternative in the event that you find yourself in a position where you can't use GPO for whatever reason.

This works flawlessly and gives you great flexibility on how you set your users printers. This is especially pertinent in older versions of Windows RDS servers.

Here is how to set the default printer for a user once they log onto your domain. You can specify different printers for different Security Groups as well...

Option Explicit 
Dim objNetwork, strDomain, strUser, objUser, objGroup, strGroupMemberships 

' Get the domain and username from the WScript.Network object 
Set objNetwork = CreateObject("WScript.Network" ) 
strDomain = objNetwork.UserDomain 
strUser = objNetwork.UserName 

' Instantiate the user object from the data above 
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser) 

' Run through the users groups 
For Each objGroup In objUser.Groups 
                If objGroup.Name = "Downstairs Xerox B&W Default Printer" Then 
                                objNetwork.SetDefaultPrinter "Xerox Black and White" 
                End If 

                If objGroup.Name = "Upstairs Xerox Upstairs Default Printer" Then 
                                objNetwork.SetDefaultPrinter "Xerox Upstairs" 
                End If     
Next

Once you have saved the above script in a shared network folder as something like SetDefaultprinter.vbs you can run it from your standard user log on script like so:

cscript.exe \\ServerName\SharedFolderName\SetDefaultprinter.vbs

 

No Comments Yet.

Leave a comment