RUNDLL and RUNDLL32 are two utilities supplied with
Windows 95 and later.
They can call DLL functions from the command line, allowing
us to create extremely powerfull batch files.
Some examples:
Start Control Panel applets (2)
General syntax:
RUNDLL32 SHELL32.DLL,Control_RunDLL filename.CPL,@n,t
where:
Examples:
An alternative approach is using CONTROL.EXE.
However, if you want to make your batch file
wait for the Control Panel applet to be closed,
you'll have to use the RUNDLL32 command with
START /WAIT
General syntax:
CONTROL.EXE filename.CPL,@n,t
where:
Examples:
Open Install new modem wizard:
RUNDLL32 modemui.dll,InvokeControlPanel
Credits: Jeffrey W. Horning (posted on JSI FAQ)
RUNDLL SYSDM.CPL,InstallDevice_Rundll
Credits: Faris Mlaeb
RUNDLL32 SHELL32.DLL,Control_RunDLL hotplug.dll
Credits: Chris S./Dx21.com
Open Device manager:
RUNDLL32 devmgr.dll DeviceManager_Execute
Credits: Jeffrey W. Horning (posted on JSI FAQ)
Install a screensaver (copy the *.SCR file to the Windows directory first) (2):
RUNDLL32 DESK.CPL,InstallScreenSaver C:\WINNT\SYSTEM32\Default.scr
(To invoke the screensaver use:
C:\WINNT\SYSTEM32\Default.scr /S
Tip by "UnhappyEggWhisk" on forums.somethingawful.com)
The directory shown is for Windows NT 4/2000, modify for Windows 9x/XP
Lock the screen (Windows 2000):
RUNDLL32 USER32.DLL,LockWorkStation
Credits: Steven Clements (posted on alt.msdos.batch.nt)
Redraw the screen (Windows 95):
RUNDLL USER,repaintscreen
Credits: Faris Mlaeb
Rearrange the windows on the screen (Windows 95):
Credits: Faris Mlaeb
Change screen resolution (Windows 9x with PowerToys' QuickRes installed):
RUNDLL DESKCP16.DLL,QUICKRES_RUNDLLENTRY hresxvresxbpp
Where hres is the horizontal resolution in pixels,
vres is the vertical resolution in pixels, and
bpp is the number of bits per pixel.
The following example will set the screen resolution to
800 x 600 at 256 colors (28 colors = 8 bits per pixel)
RUNDLL DESKCP16.DLL,QUICKRES_RUNDLLENTRY 800x600x8
Credits: William Allen (posted on alt.msdos.batch)
Disable mouse and/or keyboard (Windows 9*/ME):
RUNDLL KEYBOARD,DISABLE
RUNDLL MOUSE,DISABLE
There is an ENABLE function too, but I haven't found the right syntax yet. Without any further parameters it only halts the system without warning (Windows 95). You will probably need the other RUNDLL commands to do a "clean" reboot.
Credits: Koro das Master
Halt system:
RUNDLL MOUSE,ENABLE
Credits: Faris Mlaeb
Start "Add New Printer" wizard:
RUNDLL32 SHELL32.DLL,SHHelpShortcuts_RunDLL AddPrinter
Open "Connect to Printer" dialog:
RUNDLL32 WINSPOOL.DRV,ConnectToPrinterDlg
This commands opens the "Connect to Printer" dialog, as you might have guessed. I don't see any useful application yet, but maybe you do.
Open the Printers folder:
RUNDLL32 SHELL32.DLL,Control_RunDLL MAIN.CPL @2
or for Windows 2000:
RUNDLL32 SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder
Credits: Pascal Rebsamen
| Note: | To create a shortcut in the Start Menu to open the Printers
folder, create a directory using one of the following commands.
|
Print a test page (Windows 95 and later; unfortunately this command does not always work):
RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintTestPage
Or for Windows 9x (source: Daniel U. Thibault):
RUNDLL32.EXE MSPrint2.DLL,RUNDLL_PrintTestPage
View or change printer settings (Windows 2000):
RUNDLL32 PRINTUI.DLL,PrintUIEntry /?
This will display an extensive list of available functions
and many examples.
View this same list in HTML.
Add a TCP/IP printer port:
RUNDLL32 tcpmonui.dll,LocalAddPortUI
Credits: Jeffrey W. Horning (posted on JSI FAQ)
Open the dialog box for editing the Favorites in Internet Explorer:
RUNDLL32.EXE shdocvw.dll,DoOrganizeFavDlg
Credits: "pradeep" (posted on Go4Expert Forum)
Start GUI mode disk format:
RUNDLL32 SHELL32.DLL,SHFormatDrive
Start GUI mode diskcopy:
RUNDLL32 DISKCOPY.DLL,DiskCopyRunDll
Credits: Media Chance
"Map Network Drive" dialog (Windows 95):
RUNDLL32 USER,wnetconnectdialog
and for Windows XP:
RUNDLL32 SHELL32.DLL,SHHelpShortcuts_RunDLL Connect
Credits: Faris Mlaeb (Windows 95) and Ian Freeman (Windows XP)
Manage shares:
RUNDLL32 ntlanui.dll,ShareManage - Shares
Credits: Jeffrey W. Horning (posted on JSI FAQ)
Create a new share:
RUNDLL32 ntlanui.dll,ShareCreate
Credits: Jeffrey W. Horning (posted on JSI FAQ)
Open the Network ID wizard:
RUNDLL32 netplwiz.dll,NetAccWizRunDll
Credits: Jeffrey W. Horning (posted on JSI FAQ)
Open the Add network place wizard:
RUNDLL32 netplwiz.dll,AddNetPlaceRunDll
Credits: Jeffrey W. Horning (posted on JSI FAQ)
Logoff Windows (1)
Reboot (1)
Shutdown (1)
Activate suspend mode (1) (Windows 2000/XP):
RUNDLL32 PowrProf.dll, SetSuspendState
Credits: TechRepublic's Windows XP Newsletter & Graham Smith.
Show Windows 9*'s "System setting changed, do you want to reboot now?" dialog (1):
RUNDLL SHELL.DLL,RestartDialog
Display NT's "About" dialog, showing version, servicepack, registered owner and amount of physical memory:
RUNDLL32 SHELL32.DLL,ShellAboutW
Open a file with Windows' "Open as" dialog:
RUNDLL32 SHELL32.DLL,OpenAs_RunDLL filename
Open a .ZIP file in Explorer (XP):
RUNDLL32.EXE ZIPFLDR.DLL,RouteTheCall zipfile.ZIP
Unfortunately, there seems to be no (native) command to copy files into the .ZIP file
Swap your mouse to left handed use (tip from "Speedy Gonzales"):
RUNDLL USER.EXE,SwapMouseButtonRUNDLL32 USER32.DLL,SwapMouseButtonI know of no command yet to undo this, but the following will get you close:
CONTROL MAIN.CPL
or:
RUNDLL32 SHELL32.DLL,Control_RunDLL MAIN.CPL,@0,1
Start "DialUp Connection" Wizard (Windows 95):
RUNDLL RNAUI.DLL,RnaWizard
Credits: Faris Mlaeb
Start DialUp Network:
START RUNDLL32 RNAUI.DLL,RnaDial exact name of dialer entry
TRACERT -h 1 -w 1
The RUNDLL command starts DUN, the TRACERT command
is supposed to actually start the dialing process, assuming
automatic dialing is enabled.
Since I do not have access to any PC with DUN installed,
I could not test the TRACERT command's effect.
Credits for these commands: Michael J. Gregg and Tom Lavedas
Use the RASPHONE command in Windows NT, which can also hang up the connection
Credits: Simon Sheppard.
Open the Fonts folder:
RUNDLL32 SHELL32.DLL,SHHelpShortcuts_RunDLL FontsFolder
Credits: Media Chance
TechRepublic's Windows XP e-Newsletter for August 5, 2004, showed a nice example of using RUNDLL32 to open an Active Directory Search window:
RUNDLL32 dsquery,OpenQueryWindow
This allows you to search Active Directory for users or computers, though only a limited part of the properties is accessible.
Activate registry changes in HKEY_CURRENT_USER without logging off (Windows 2000 and later):
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True
Credits: Pete Smith.
Remove Messenger (Windows XP):
RUNDLL32 advpack.dll,LaunchINFSection %windir%\INF\msmsgs.inf,BLC.Remove
Credits: Pascal Rebsamen (posted on WinBoard)
Repair IE 6 (Windows XP):
RUNDLL32 setupapi,InstallHinfSection DefaultInstall 132 %windir%infie.inf
Credits: Pascal Rebsamen (posted on WinBoard)
| Notes: | (1) | See my Shutdown page for more information and examples on reboot and shutdown command lines. |
| (2) | By associating *.CPL files with the command
RUNDLL32 SHELL32.DLL,Control_RunDLL %1,@0
and *.SCR files with
RUNDLL32 DESK.CPL,InstallScreenSaver %1
you can open and/or install them by doubleclicking on their icons. |
The following batch file installs a screensaver if one is specified, and opens the Control Panel applet at the right tab to enable adjustment of its settings (tested in NT only):
@ECHO OFF
IF "%1"=="" GOTO Interactive
IF NOT EXIST %SystemRoot%.\System32\%~nx1 GOTO Interactive
RUNDLL32 DESK.CPL,InstallScreenSaver %~f1
GOTO End
:Interactive
RUNDLL32 SHELL32.DLL,Control_RunDLL DESK.CPL,@0,1
:End
An extensive list of RUNDLL commands with good search capabilities can be found at Dx21's RunDLL32 section.
For programmers, there is more information on Microsoft's
Windows
95 Rundll and Rundll32 Interface page.
On Robert Vivrette's
The
Unofficial Newsletter of Delphi Users you can find an article about
RUNDLL by Wendell Jones (brought to my attention by William Brooks in
response to my request for tips; thanks).
Peter A. Bromberg's Short RunDll32 Primer for Developers.
How INF files work by Mike Williams.
At The Visual Basic Developers Resource Centre a list of Control Panel Functions for Windows 9x/NT through RUNDLL can be found (a tip from my former collegue Adriaan Westra; thanks).
An extensive list of Control Panel related and other RUNDLL commands can be found at Media Chance's RUNDLL FAQ page.
Jeffrey W. Horning provided a list of Undocuments paths to Windows 2000 tools (thanks for Viju Chellamuthu, who mailed me the link).