Pages

10/14/2002

Windows 9X, NT :: Automation
From: HTTP://WWW.ROBVANDERWOUDE.COM

RUNDLL and RUNDLL32


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:
Start Control Panel applets (2):
General syntax:
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
Examples:
Date/time applet, Time Zone tab:
RUNDLL32 SHELL32.DLL,Control_RunDLL TIMEDATE.CPL,@0,1
Desktop applet, Screensaver tab:
RUNDLL32 SHELL32.DLL,Control_RunDLL DESK.CPL,@0,1
Network applet, Protocols tab:
RUNDLL32 SHELL32.DLL,Control_RunDLL NCPA.CPL,@0,2
Network applet, Adapters tab:
RUNDLL32 SHELL32.DLL,Control_RunDLL NCPA.CPL,@0,3
System applet, Environment tab:
RUNDLL32 SHELL32.DLL,Control_RunDLL SYSDM.CPL,@0,2
Start "Add New Hardware" Wizard (Windows 95):
RUNDLL SYSDM.CPL,InstallDevice_Rundll
Credits: Faris Mlaeb

Start "DialUp Connection" Wizard (Windows 95):
RUNDLL RNAUI.DLL,RnaWizard
Credits: Faris Mlaeb

Install a screensaver (copy the *.SCR file to the Windows directory first) (2):
RUNDLL32 DESK.CPL,InstallScreenSaver C:\WINNT\SYSTEM32\Default.scr
The directory shown is for Windows NT/2000/XP, modify for Windows 9x

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):
Cascade:
RUNDLL32 USER,cascadechildwindows
Tile:
RUNDLL32 USER,tilechildwindows
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 (8 bits)
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

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
Credits: Faris Mlaeb

Logoff Windows (1)
Logoff Windows 98:
RUNDLL SHELL32.DLL,SHExitWindowsEx

Logoff Windows 98 and run Explorer after relogon:
RUNDLL SHELL32.DLL,SHExitWindowsEx 4

Logoff Windows NT 4:
RUNDLL32 USER32.DLL,ExitWindowsEx
RUNDLL32 USER32.DLL,ExitWindowsEx
This is not a mistake, the command usualy must be called twice before anything happens.

Reboot (1)
Windows 95 (not reliable, sometimes only shutdown):
RUNDLL USER.EXE,ExitWindowsExec
Windows 98:
RUNDLL SHELL32.DLL,SHExitWindowsEx 2
Windows NT 4:
@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)

Shutdown (1)
Windows 95:
RUNDLL USER.EXE,ExitWindows

Windows 98:
RUNDLL SHELL32.DLL,SHExitWindowsEx 1

or:
RUNDLL32 KRNL386.EXE,exitkernel

(will also power down ATX boards)

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

Swap your mouse to left handed use (tip from "Speedy Gonzales"):
Windows 95:
RUNDLL USER.EXE,SwapMouseButton

Windows NT:
RUNDLL32 USER32.DLL,SwapMouseButton
I 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 Network:
(Credits for these commands: Michael J. Gregg and Tom Lavedas)
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.
Use the RASPHONE command in Windows NT, which can also hang up the connection (credits: Simon Sheppard).

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.
Windows 9x (without roaming profiles):
MD "%windir%\Start Menu\Programs\Printers.{2227A280-3AEA-1069-A2DE-08002B30309D}"
Windows NT 4/2000:
MD "%USERPROFILE%\Start Menu\Programs\Printers.{2227A280-3AEA-1069-A2DE-08002B30309D}"

Open the Fonts folder:
RUNDLL32 SHELL32.DLL,SHHelpShortcuts_RunDLL FontsFolder
Credits: Media Chance

Print a test page:
RunDLL32.EXE SHELL32.DLL,SHHelpShortcuts_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.
This list can also be viewed here.
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 .
More Information
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 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).
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.
Many more RUNDLL commands in German are available at Pascal Rebsamen's Windows 2000: RunDLL32 page.

No comments: