.SetDefaultPrinter - VBScript


## Overview

.SetDefaultPrinter sets the default printer for the current user. This is useful for setting up a default printer for a specific user account or for use in scripts or batch files.

## Syntax

.SetDefaultPrinter(PrinterName)

Parameters:

  • PrinterName: The name of the printer to set as the default. The printer name must be a valid printer driver installed on the system.

## Options/Flags

This command does not have any options or flags.

## Examples

Set objShell = CreateObject("WScript.Shell")
objShell.SetDefaultPrinter "HP LaserJet P1102w"

This example sets the default printer to “HP LaserJet P1102w”.

## Common Issues

  • Error: “Invalid printer name”

This error occurs when the specified printer name is not valid or is not a valid printer driver installed on the system. Verify that the printer name is correct and is a valid printer driver installed on the system.

  • Error: “Access denied”

This error occurs when the user does not have sufficient permissions to set the default printer. Ensure that the user has the “Manage Printers” permission or is an administrator.

## Integration

.SetDefaultPrinter can be combined with other VB Script commands to automate printer management tasks. For example, you can use it in a script that:

  • Checks if a printer is installed on the system
  • Sets the default printer based on the user’s preferences
  • Removes a printer from the system

## Related Commands

  • .GetDefaultPrinter
  • .InstallPrinter
  • .RemovePrinter