Someone asked this question a few days ago.
I wanted to know how to click the ok button in the windows login dialog.
So I found out.
Code:
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	HWND handle; //handle to a window
    printf("Waiting for login dialog\n");
    for(;;){ //main loop
        handle = FindWindow(NULL, "Enter Network Password"); //The window I'm looking for

        if(handle){
            printf("Login dialog found");
            SendMessage(handle, WM_COMMAND, 0x00000001, 0x000000c8); //see notes
            break; //exit loop
        }    
    }
    //exit(0);

	return 0;
}

//Notes:
// Using spy++ I viewed the messages sent to the login window.
// I only care about the WM_COMMAND messages sent to this window
// Seeing the message directed to a window object (say... a button 0xc8),
// you can easly get the pram. 0x1 basicly tells 0xc8 that it has been clicked.
// Very useful when you have a nat server on win98. CRASH