RunDLL32.exe

Run a 32 bit DLL function.
Rundll32 is available on all version of Windows from Windows 95 onwards, but only runs in 32 bit mode.

Syntax
       RUNDLL32.EXE dll_name,EntryPoint [optional_arguments]

       RUNDLL32 printui.dll PrintUIEntry [baseParameter] [modificationParameter1]
          [modificationParameter2] [modificationParameterN]

Key
   dll_name     A full path to the DLL to ensure that the correct one is found.
                For best results, use the short file name.

   EntryPoint   The name of the entry point function.

Base Parameters:

   /dl  Delete the local printer.
   /dn  Delete a network printer connection.
   /dd  Delete a printer driver.

   /e   Display the printing preferences for a given printer.

   /ga  Add a per computer printer connection
        (the connection is available to any user on that computer when they log on).
   /ge  Display per computer printer connections on a computer.
   /gd  Delete a per computer printer connection
        (the connection is deleted the next time a user logs on).

   /ia  Install a printer driver by using an .inf file.
   /id  Install a printer driver by using the add printer Driver Wizard.
   /if  Install a printer by using an .inf file.
   /ii  Install a printer by using the add printer wizard with an .inf file.
   /il  Install a printer by using the add printer wizard.
   /in  Connect to a remote network printer.
   /ip  Install a printer by using the Network printer Installation Wizard
        (available from the user interface from print Management).

   /k   print a test page on a printer.

   /o   Display the queue for a printer.

   /p   Display the properties of a printer.
        When you use this parameter, you must also specify a value for the
        modification parameter /n[name].

   /s   Display the properties of a print server.
        If you want to view the local print server, you do not need to use a modification parameter.
        However, if you want to view a remote print server, you must specify the /c[name] modification parameter.

   /Ss  Specifies what type of information for a printer will be stored.
        If none of the values for /Ss are specified, the default behavior is as if all of them were specified.
        Use this base parameter with the following values placed at the end of the command line:

         2: Stores the information contained in the printer s printER_INFO_2 structure.
            This structure contains the basic information about the printer such as its name, server name,
            port name, and share name.
         7: Used to store the directory service information contained in the printER_INFO_7 structure.
         c: Stores the color profile information for a printer.
         d: Stores printer specific data such as the printer s hardware ID.
         s: Stores the printer's security descriptor.
         g: Stores the information in the printer's global DEVmode structure.
         m: Stores the minimal settings for the printer. This is equivalent to specifying 2 d, and g.
         u: Stores the information in the printer's per user DEVmode structure.

   /Sr   Specifies what information about a printer is restored and how conflicts in settings are handled.
         Use with the following values placed at the end of the command line:

         2: Restores the information contained in the printer s printER_INFO_2 structure.
            This structure contains the basic information about the printer such as its name, server name,
            port name, and share name.
         7: Restores the directory service information contained in the printER_INFO_7 structure.
         c: Restores the color profile information for a printer.
         d: Restores printer specific data, such as the printer s hardware ID.
         s: Restores the printer s security descriptor.
         g: Restores the information in the printer s global DEVmode structure.
         m: Restores the minimal settings for the printer. This is equivalent to specifying 2, d, and g.

         u: Restores the information in the printe s per user DEVmode structure.

         r: If the printer name stored in the file is different from the name of the printer being
            restored to, then use the current printer name. This cannot be specified with f.
            If neither r nor f is specified and the names do not match, restoration of the settings fails.

         f: If the printer name stored in the file is different from the name of the printer being
            restored to, then use the printer name in the file. This cannot be specified with r.
            If neither f nor r is specified and the names do not match, restoration of the settings fails.

         p: If the port name in the file being restored from does not match the current port name of the
            printer being restored to, the printer's current port name is used.

         h: If the printer being restored to could not be shared using the resource share name in the
            saved settings file, then attempt to share the printer with either the current share name or
            a new generated share name. If neither H nor h is specified and the printer being restored to
            cannot be shared with the saved share name, then restoration fails.

         h: If the printer being restored to cannot be shared with the saved share name, then do not share
            the printer. If neither H nor h is specified and the printer being restored to cannot be shared
            with the saved share name, then restoration fails.

         i: If the driver in the saved settings file does not match the driver for the printer being restored
            to, then the restoration fails.
            
   /Xg   Retrieve the settings for a printer.
   /Xs   Set the settings for a printer.
   /y    Set the printer being installed as the default printer.
   /?    Display in-product help for the command and its associated parameters.
   @[file]   Specifies a command-line argument file and directly inserts the text in that file into the command line.
   
Modification Parameters:

   /a[file]   The binary file name.
   /b[name]   The base printer name.
   /c[name]   The computer name if the action to be performed is on a remote computer.
   /f[file]   The Universal Naming Convention (UNC) path and name of the .inf file name or the output
              file name, depending on the task that you are performing. Use /F[file] to specify a dependent .inf file.
   /F[file]   The UNC path and name of a .inf file that the .inf file specified with /f[file] depends on.
   /h[architecture]  The driver architecture. Use one of the following: x86, x64, or Itanium.
   /j[provider]   The print provider name.
   /l[path]   The UNC path where the printer driver files that you are using are located.
   /m[model]  The driver model name. (This value can be specified in the .inf file.)
   /n[name]   The printer name.
   /q         Runs the command with no notifications to the user.
   /r[port]   The port name.
   /u         Specifies to use the existing printer driver if it is already installed.
   /t[#]      The zero-based index page to start on.
   /v[version]  The driver version. If you do not also specify a value for /K, you must specify one of
               the following values: type 2 - Kernel mode or type 3 - User mode.
   /w   Prompt the user for a driver if the driver is not found in the .inf file that is specified by /f.
   /Y   Do not automatically generate printer names.
   /z   Do not automatically share the printer being installed.
   /K   Change the meaning of the parameter /h[architecture] to accept 2 in place of x86, 3 in place of x64, or
        4 in place of Itanium. This also changes the value of the parameter /v[version] to accept 2 in the place of
        type 2 - Kernel mode and 3 in place of type 3 - User mode.
   /Z   Share the printer that is being installed. Only use with the /if parameter.
   /Mw[message]   Display a warning message to the user before committing the changes specified in the command line.
   /Mq[message]   Display a confirmation message to the user before committing the changes specified in the command line.
   /W[flags]   Specifies any parameters or options for the add printer wizard, the add printer Driver Wizard, and the
               Network printer Installation Wizard.

   r:          Enable wizards to be restarted from the last page.
   /G[flags]   Specifies global parameters and options that you want to use.
               w: Suppresses setup driver warnings to the user.
               
Help - Display all the available commands for PrintUI.dll:

   RUNDLL32 printui.dll,PrintUIEntry /?

The dll_name and the EntryPoint function name can be separated by either a space ( ) or a comma (,)

In some cases two or more commas are required, for example here we pass the value 1 as the second argument to Intl.cpl:

Rundll32.exe shell32.dll,Control_RunDLL Intl.cpl,,1

DLL options may be case sensitive, Rundll32 may also fail if there is any additional white space in between the dll_name, the comma, and the EntryPoint function. If you pass the wrong type of DLL to Rundll32, it may fail to run without returning any error message.

Rundll32 was originally designed only for internal use at Microsoft, it is called by control panel applets. To use them correctly requires the DLL being called to include a suitable function signature to match the operation you are calling. Details in Q164787.
RUNDLL32 printui.dll has been fully documented by Microsoft and so is safe to use.

The PrintUIEntry keyword is case sensitive, and you must enter the syntax for this command with the exact capitalization shown in the examples in this topic.

The internet has many lists of Rundll32 'cheat codes' [example], that do mostly work, but many are calling an invalid or missing function signature. This means there is a chance they may stop working (or start working in a different way) after some future Windows update.
There are often more robust methods to achieve the same thing such as Start Run commands or Shell: folder shortcuts.

Examples

Add a new remote printer printer64, for a computer, Client1, which is visible for the user account where this command is run:

RUNDLL32 printui.dll PrintUIEntry /in /n\\client1\printer64

Add a printer using the add printer wizard and using an .inf file:

RUNDLL32 printui.dll PrintUIEntry /ii /f c:\install\InfFile.inf

Add a Network Printer:

RUNDLL32 printui.dll,PrintUIEntry /ia /c\\server /m "AGFA-AccuSet v52.3"
   /h "Intel" /v "Windows 2000" /f %windir%\inf\ntprint.inf

Add a Local Printer:

RUNDLL32 printui.dll,PrintUIEntry /if /b "Test Printer" /c\\SERVER
   /f "%windir%\inf\ntprint.inf" /r "lpt1:" /m "AGFA-AccuSet v52.3"

Add a printer connection that’s available to anyone who logs on (the connection will be applied when a user logs on):

Rundll32 printui.dll,PrintUIEntry /ga /n\\Server\PrintShare1

Remove a printer connection, PrintShare1, from all users of a computer, Client2, type (the connection will be deleted when a user logs on):

RUNDLL32 printui.dll PrintUIEntry /gd /n\\client2\PrintShare1

Display the per-Machine printer connections:

RUNDLL32 printui.dll,PrintUIEntry /ge /c"\\workstation64"

View the properties of the print server, printServer1:

RUNDLL32 printui.dll PrintUIEntry /s /t1 /c\\printserver1

View the properties of a printer, printer3, type:

rundll32 printui.dll PrintUIEntry /p /n\\printer3

Delete an existing printer, printer64, on a computer, Client1

RUNDLL32 printui.dll PrintUIEntry /dn /n\\client1\printer64

Lock workstation:

RUNDLL32.exe user32.dll, LockWorkStation
n.b. this is an unsupported hack, which may fail in the future - details on oldnewthing
A PowerShell function: Lock-WorkStation is supported.

“If you're rich you can buy books. If you're poor, you need a library” ~ John Kenneth Galbraith

Related commands

Qchange.vbs - Change Printer Connection.
PRNCNFG - Configure or rename a printer.
PRNMNGR - Add, delete, list printers and printer connections.
REGSVR32 - Register or unregister a DLL.
WMIC PRINTER - Set printing options through WMI.
Q164787 - Rundll32 command line.
PowerShell: Get-CIMinstance - Get WMI information.


 
© BACK 2 Rank aka Tracer
"Lameness is not a reason for suicide but posing with eliteness is a reason for murders"