RUNDLL and RUNDLL32 are two utilities supplied with
Windows 95/98 and NT.
They can call DLL functions from the command line, allowing
us to create extremely powerfull batch files.
Some examples:
RUNDLL32 SHELL32.DLL,Control_RunDLL filename.CPL,@n,t
where | filename.CPL | is the name of one of Control Panel's *.CPL files, | ||
n | is the zero based number of the applet within the *.CPL file, and | |||
t | is the number of the tab for multi paged applets | |||
RUNDLL32 SHELL32.DLL,Control_RunDLL TIMEDATE.CPL,@0,1
RUNDLL32 SHELL32.DLL,Control_RunDLL DESK.CPL,@0,1
RUNDLL32 SHELL32.DLL,Control_RunDLL NCPA.CPL,@0,2
RUNDLL32 SHELL32.DLL,Control_RunDLL NCPA.CPL,@0,3
RUNDLL32 SHELL32.DLL,Control_RunDLL SYSDM.CPL,@0,2
RUNDLL32 DESK.CPL,InstallScreenSaver C:\WINNT\SYSTEM32\Default.scr
The directory shown is for Windows NT, adjust for
Windows 95/98
RUNDLL32 SHELL32.DLL,SHHelpShortcuts_RunDLL AddPrinter
RUNDLL32 SHELL32.DLL,SHFormatDrive
RUNDLL SHELL32.DLL,SHExitWindowsEx
RUNDLL SHELL32.DLL,SHExitWindowsEx 4
RUNDLL32 USER32.DLL,ExitWindowsEx
RUNDLL32 USER32.DLL,ExitWindowsEx
This is not a mistake, the command usualy must be
called twice before anything happens.
RUNDLL USER.EXE,ExitWindowsExec
RUNDLL SHELL32.DLL,SHExitWindowsEx 2
@ECHO OFF
PUSHD %temp%
ECHO [Version] > {out}.inf
ECHO signature=$chicago$ >> {out}.inf
ECHO [defaultinstall] >> {out}.inf
RUNDLL32 SETUPAPI,InstallHinfSection DefaultInstall 1 {out}.inf
DEL {out}.inf
POPD
(original batch file by Walter Zackery,
adapted for readability)
RUNDLL USER.EXE,ExitWindows
RUNDLL SHELL32.DLL,SHExitWindowsEx 1
RUNDLL SHELL.DLL,RestartDialog
RUNDLL32 SHELL32.DLL,ShellAboutW
RUNDLL32 SHELL32.DLL,OpenAs_RunDLL filename
RUNDLL USER.EXE,SwapMouseButton
RUNDLL32 USER32.DLL,SwapMouseButton
CONTROL MAIN.CPL
or:
RUNDLL32 SHELL32.DLL,Control_RunDLL MAIN.CPL,@0,1
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.
Since I do not have access to any PC with DUN installed,
I could not test the TRACERT command's effect.
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.
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 Interact
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
I am interested to hear about other possible uses for RUNDLL. Please send me your tips or comments by e-mail: info@robvanderwoude.com . |
For programmers, there is more information on Microsoft's INFO: The Windows 95 Rundll and Rundll32 Interface page and 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 this request for tips; thanks).
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 collegue Adriaan Westra; thanks).