Creating process to run IE on new Windows desktop

2019-07-23 08:19发布

I'm trying to set up an IE kiosk which runs IE on a separate desktop. While I'm testing I'm just starting IE normally (not in kiosk mode), but although IE starts up on the new desktop it doesn't load the initial page specified in the command string, it just sits there with the hourglass flickering on and off really quickly (even when I move the mouse elsewhere on the desktop, outside the IE window). There is no URL displayed in the navigation box. I can access the menus and so on inside IE, but even if I type in a URL by hand nothing happens. Closing IE takes me back to the default desktop as expected.

A couple of extra things I tried: launching a command prompt (works fine, and I can ping the site I'm trying to connect to, so Internet access from the new desktop isn't blocked); launching Notepad with a filename parameter (works fine, opens the specified file, so I'm passing the command-line parameter correctly).

This is my code; any thoughts welcomed:

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
  char* desktop   = "MyDesktop";

  HDESK hThreadDT = GetThreadDesktop(GetCurrentThreadId());
  HDESK hInputDT  = OpenInputDesktop(0, FALSE, DESKTOP_SWITCHDESKTOP);
  HDESK hNewDT    = CreateDesktop(desktop, NULL, NULL, 0, GENERIC_ALL, NULL);

  SetThreadDesktop(hNewDT);
  SwitchDesktop(hNewDT);

  if (SetCurrentDirectory("C:\\Program Files\\Internet Explorer")) {
    PROCESS_INFORMATION pi;
    STARTUPINFO si;

    memset(&pi, 0, sizeof(pi));
    memset(&si, 0, sizeof(si));
    si.cb = sizeof(si);
    si.lpDesktop = desktop;

    if (CreateProcess(NULL, "iexplore.exe http://www.google.com",
                      NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
      WaitForSingleObject(pi.hProcess,INFINITE);
    }
    else {
      char msg[1000];
      wsprintf(msg,"CreateProcess failed (%d)",GetLastError());
      MessageBox(NULL,msg,NULL,MB_OK);
    }
  }

  SwitchDesktop(hInputDT);
  SetThreadDesktop(hThreadDT);
  CloseDesktop(hNewDT);

  return 0;
}

1条回答
Rolldiameter
2楼-- · 2019-07-23 08:53

Try passing the following command line to CreateProcess (more info):

"iexplore.exe -k -noframemerging http://www.google.com"

You also have an option to automate Internet Explorer via OLE InternetExplorer.Application object, particularity with put_Visible, put_FullScreen and Navigate2 methods.

查看更多
登录 后发表回答