A Short RunDll32 Primer for Developers

by Peter A. Bromberg, Ph.D.

Peter Bromberg
"In the end, we will remember not the words of our enemies, but the silence of our friends." --Dr. Martin King

WHAT IS RUNDLL?

What is "rundll"? The Rundll and Rundll32 utility programs were originally designed only for internal use at Microsoft. But the functionality provided by them is sufficiently generic that they are now available for general use. Rundll32 loads and runs 32-bit DLLs, and since 99.9% of what we are working with here is 32-bit, that is where we will focus. 64-bit, we don't need to worry about since the 64-bit platforms will SysWow all these calls happily into their 32-bit counterparts.



RUNDLL32 SYNTAX

The command line for Rundll is as follows:

RUNDLL32.EXE <dllname>,<entrypoint> <optional arguments>


An example:

RUNDLL.EXE SETUPX.DLL,InstallHinfSection 132 C:\WINDOWS\INF\SHELL.INF

The DLL name may not contain any spaces, commas or quotation marks. If the DLL name does contain spaces, use the short (8.3) version of the file name. Note that there must be a comma between the DLL name and the entry point. Also, the name of the entry point function is case-sensitive, and there can't be any spaces between the DLL name, the comma, and the entry point function name. If the DLL file is not in a folder contained in the system path environment, then the full path must be used for the DLL name.

How Rundll Works

1. It parses the command line.
2. It loads the specified DLL via LoadLibrary().
3. It obtains the address of the <entrypoint> function via GetProcAddress().
4. It calls the <entrypoint> function, passing the command line tail which is the <optional arguments>.
5. When the <entrypoint> function returns, Rundll.exe unloads the DLL and exits.

You can call a RunDll32 command from a batch file, and you can use the .NET Framework Process class.


SOME BASIC RUNDLL32 COMMANDS

CONTROL PANEL APPLETS rundll32 shell32,Control_RunDLL <your-favorite-control-panel-applet-filename>

ADD NEW DEVICE rundll32 wiashext.dll,AddDeviceWasChosen

RUN HOME NETWORKING WIZARD
rundll32 %SystemRoot%\System32\hnetwiz.dll,HomeNetWizardRunDll

"%windir%\System32\rundll32.exe user32.dll, LockWorkStation"

Perform "idle time" optimization tasks
rundll32.exe advapi32.dll,ProcessIdleTasks

Add a new printer:RUNDLL32 SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder

GENERAL RUNDLL32 COMMANDS REQUIRING A %1 ARGUMENT

CREATE NEW SHORTCUT rundll32.exe appwiz.cpl,NewLinkHere %1 (folder where link will be created)

INSTALL INF FILE %SystemRoot%\System32\rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 %1

RUN .DUN FILE %SystemRoot%\system32\RUNDLL32.EXE NETSHELL.DLL,InvokeDunFile %1 (INSTALL OR JUST CONNECT?)

rundll32.exe %SystemRoot%\System32\shimgvw.dll,ImageView_Fullscreen %1

rundll32.exe desk.cpl,InstallScreenSaver %l (screensaver name)


PERFORM A FORCE REINSTALL of Internet Explorer 6.0 (can be used when IE 7 Beta cannot be uninstalled):

rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 C:\windows\inf\ie.inf

SELECTED %L RUNDLL32 COMMANDS

rundll32 cdfview.dll,OpenChannel %L

rundll32 cdfview.dll,Subscribe %L

rundll32.exe shdocvw.dll,OpenURL %l

rundll32 cdfview.dll,OpenChannel %L

Perform "idle time" optimization tasks:

rundll32.exe advapi32.dll,ProcessIdleTasks

Running a command line tool and keeping the console window open:

%comspec% /k <command here>

rundll32.exe appwiz.cpl,NewLinkHere %1

USING THE PROCESS CLASS WITH RUNDLL32

// display control panel
Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL");

// display the add remove programs applet
Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL appwiz.cpl");

// display the network applet
Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL ncpa.cpl");

If you have certain things that you need to do when a user configures a program you have developed, RunDll32 can be incorporated into the setup routine and can help you solve a number of problems for which there may not appear to be a readily available solution. For example, you could add buttons in your Configuration Screen that make calls to the above applets and provide instructions to the user. There are several RunDll32 command references available, here is one that may be helpful


Peter Bromberg is a C# MVP, MCP, and .NET consultant who has worked in the banking and financial industry for 20 years. He has architected and developed web - based corporate distributed application solutions since 1995, and focuses exclusively on the .NET Platform.
Article Discussion: