Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Rundll32 to execute DLL Function?

Tags:

rundll32

Using the ShellExecute documentation as a reference:

I run the following from the command line:

C:\>RUNDLL32.EXE SHELL32.DLL,ShellExecute handle,"open","C:\Documents and Settings\admin\Desktop\tmp",NULL,NULL,SW_SHOWNORMAL

This results in an exception error.

I don't know what this means:

HINSTANCE ShellExecute(
  __in_opt  HWND hwnd,
  __in_opt  LPCTSTR lpOperation,
  __in      LPCTSTR lpFile,
  __in_opt  LPCTSTR lpParameters,
  __in_opt  LPCTSTR lpDirectory,
  __in      INT nShowCmd
);

But in the description, a handle (HWND), and a pointer to a null-terminated string (LPCTSTR), are mentioned, but it is very confusing.

Any help would be greatly appreciated. I would also like to learn more, so any references (book, web links, etc) would also be great!

like image 986
mike Avatar asked Jul 08 '10 19:07

mike


People also ask

How do I run a DLL file with rundll32?

There are no configurable settings for Rundll32. Help information is provided for a specific DLL you run with the rundll32 command. You must run the rundll32 command from an elevated command prompt. To open an elevated command prompt, click Start, right-click Command Prompt, and then click Run as administrator.

What is rundll32.exe command?

EXE. As the name suggest, the “rundll32.exe” executable is used to “RUN DLL's” or Dynamic Link Libraries (Below is the definition of a DLL from MSDN).


1 Answers

Rundll32 only supports running DLL exports with the following signature:

void CALLBACK
  EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

It does not support running arbitrary entry points. Since ShellExecute does not have that signature, clearly bad things will happen.

INFO: Windows Rundll and Rundll32 Interface has more info on the rundll32 interface.

If you want to do the equivelent of ShellExecute from the command line, just use start:

C:\>start "C:\Documents and Settings\admin\Desktop\tmp"
like image 65
Michael Avatar answered Oct 05 '22 07:10

Michael