CreateProcess ShellExecute

1、用CreateProcess调用regsvr32注册dll

    PROCESS_INFORMATION ProcessInfo;
    STARTUPINFO StartupInfo;
    ZeroMemory(&StartupInfo,sizeof(StartupInfo));
    StartupInfo.cb = sizeof StartupInfo;

    _tcscat(path, _T("//Test.dll/" /s"));//path:Test.dll的目录,目录有空格要加引号“C:/Program Files/Test.dll”
    TCHAR szPath[MAX_PATH]={0};
    _tcscpy(szPath,_T("regsvr32.exe /""));
    _tcscat(szPath,path);
    if(CreateProcess(NULL,szPath,NULL,NULL,FALSE,0,NULL,NULL,&StartupInfo,&ProcessInfo) )
    {

        //注册成功的话,等待注册完成
        WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
        CloseHandle(ProcessInfo.hThread);
        CloseHandle(ProcessInfo.hProcess);
    }

2、用ShellExecute调用regsvr32注册dll

TCHAR path[30]=_T("/"C:/Program Files/Test.dll/" /s");// /s:取消弹出提示框

HINSTANCE hInstance = ShellExecute(NULL,_T("open"),_T("regsvr32.exe"),_T("navigator.dll /s"),path,SW_HIDE);

 

3、调用 ShellExecute 打开浏览器

  a.打开IE浏览器,会打开一个新的IE窗口:

HINSTANCE  hInstance = ShellExecute(NULL,NULL,_T("IEXPLORE"),_T("http://www.baidu.com"),NULL,SW_NORMAL);//

  b.打开默认浏览器,不是在新的默认浏览器中打开,如果默认浏览器没启动的话,可能会有问题

ShellExecute(NULL, "open", "http://www.csdn.net", NULL,NULL,SW_SHOWMAXIMIZED);

  c.打开默认浏览器,无论默认浏览器是否打开,都可实现

CString args;

args.Format(_T("url.dll,FileProtocolHandler http://www.csdn.net"));//

HINSTANCE result = ShellExecute(NULL, _T("open"), _T("rundll32.exe"), args, NULL, SW_SHOWNORMAL);

 

你可能感兴趣的:(c,浏览器,IE,null,dll,Path)