IMPORTANT: The information in this article is designed for use by corporate administrators. Before you use any of the methods that are described in this article in your environment, you should thoroughly test the method in a test environment.
Printers are designed to roam with a user's roaming profile, and this is why the default printer is stored under the HKEY_CURRENT_USER branch of the registry. To alter this behavior, use either of the following methods.
Method 1Export the default printer setting for an already-installed printer, and then merge the setting into the user's profile when the user logs on to the computer:
- Use Registry Editor (Regedit.exe) to export the following registry key:HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows
- Modify the registry (.reg) file you made in step 1 with a text editor so that the only registry value name below the key is:
"Device"=...Note that the registry file should contain a blank line at the bottom of the file.
- Use Registry Editor (Regedit.exe) to add a new ResetPrinter string value under the following registry key:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
- The value of the ResetPrinter value should be something similar to the following valueREGEDIT.EXE -S path\File.regwhere File.reg is the name you used to store the default printer.
Method 2If computers in a specific area contain similar computer names, you can use a .vbs script file that matches a specific set of characters in the computer name, and installs a corresponding printer. The sample code that is included in this method only requires that you modify the IF lines. For example, the first IF statement in the code translates to "if the computer name contains the text "LAB1-", then set the default printer to "\\LAB1\LaserJet". To complete this method:
- Copy the following sample VBS code into a . vbs file, for example, Defaultprinter.vbs:
DIM RegEntry, ComputerName
ComputerName = ReadRegValue(RegEntry)
if InStr(1,ucase(ComputerName),"LAB1-",vbTextCompare) > 0 then call SetPrinter("\\LAB1\LaserJet")
if InStr(1,ucase(ComputerName),"LAB2-",vbTextCompare) > 0 then call SetPrinter("\\LAB2\LaserJet")
if InStr(1,ucase(ComputerName),"OFFICE-",vbTextCompare) > 0 then call SetPrinter("\\OFFICE\LaserJet")
'so on and so forth.
' *** This subroutine installs and sets the default printer
Sub SetPrinter(ByVal PrinterPath)
Set WshNetwork = CreateObject("WScript.Network")
' **** This function returns the data in the registry value
Function ReadRegValue(ByVal RegValue)
Set WSHShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
- Modify the IF lines as needed. The only portion of the IF lines that need to be modified is between double quotes. Note that you may need to add additional IF lines.
- Use Registry Editor to create a ResetPrinter string value under the following registry key:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
- The value of ResetPrinter should be something similar to the following valueWSCRIPT.EXE path\DefaultPrinter.vbswhere path is the location where the Defaultprinter.vbs file is stored.
NotesIt is also possible to run the Defaultprinter.vbs file from a login script instead of the run key. Both of the methods that are described in this article reset the default printer that a user's profile is set to print to. Also, if the sample script that is included in this article does not run properly, you may need to upgrade or install the Windows Scripting Host from the following Microsoft Web site:
ID articol: 304767 - Ultima examinare: 19 iun. 2014 - Revizie: 1