日常工作问题总结(三十二)shellExecute、shellExecuteEx、WinExec、CreateProcess的区别
来源:互联网 发布:org.apache.http.impl 编辑:程序博客网 时间:2024/06/06 00:50
shellExecute,shellExecuteEx,WinExec,CreateProcess这几个函数都可以启动一个exe(Exp:notepad.exe)文件,但是区别在哪,今天就粗略讲下我查阅资料后的结果。也希望大家提意见,发现不足之处。
1.shellExecute
(1.)打开exe应用程序(文件txt也可)
ShellExecute(NULL,"open","NOTEPAD.EXE",NULL,NULL,SW_SHOWNORMAL);(2.)打开url网址
ShellExecute(NULL, "open", "IEXPLORE", strCanonicalHref, NULL,SW_SHOWNORMAL);ShellExecute(NULL,"open",strCanonicalHref,NULL,NULL,SW_SHOWNORMAL);
strCanonicalHref存放的即要打开的网址。一种是以ie浏览器打开,下面一种是使用默认浏览器打开。
(3.)参数解析
2.shellExecuteEx
这个windows函数用的不多,但是要手动提升进程的权限时,就要用这个函数。
SHELLEXECUTEINFO sei = {sizeof(SHELLEXECUTEINFO)};sei.lpVerb = TEXT("runas");sei.lpFile = TEXT("Package.exe");sei.nShow = SW_SHOWNORMAL;if (!ShellExecuteEx(&sei)){DWORD dwError = GetLastError();}
“runas”表示使用管理员权限运行。
3.WinExec
UINT Win Exec(LPCSTR lpCmdLine, UINT uCmdShow);
(3.) 使用:
WinExec("notepad.exe",SW_SHOW);//运行计事本
4.CreateProcess
if( !CreateProcess( NULL, (LPSTR)strGamePath.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &m_ClientSI, &m_ClientPI) ) { ZeroMemory( &m_ClientSI, sizeof(m_ClientSI) ); m_ClientSI.cb = sizeof(m_ClientSI); }
可参考:工作问题总结(三十)共享内存续(当文件映射对象的名称未知时)
5.总结
(1).
winexec() 只用于可执行文件,是一个老函数啦,虽然使用方便,但不推荐!(兼容性也不好)
(2).
shellexcute()是通过windows外壳打开任意文件,非可执行文件自动通过关联的程序打开对于可执行文件,区别不大,不过shellexcute可以指定运行时的工作路径,ShellExecute不仅能打开机器上的文件,还能打开网址。
shellexecuteEx()可用来提升进程的权限。
ShellExecute 与 ShellExecuteEx 的区别是 ShellExecuteEx 可以返回新创建进程的句柄,ShellExecute在创建进程后立即调用 CloseHandle 关闭新进程句柄,而ShellExecuteEx将返回新进程序句柄。
(3).
winexec() 必须有GetMessage或超时之后才返回!CreateProcess和ShellExecute都是直接返回的!
(4).CreateProcess应该是ShellExecute / ShellExecuteEx 实现的基础。
- 日常工作问题总结(三十二)shellExecute、shellExecuteEx、WinExec、CreateProcess的区别
- ShellExecute,ShellExecuteEx, WinExec ,CreateProcess区别
- WinExec,ShellExecute ,CreateProcess 区别
- ShellExecute, WinExec, CreateProcess区别
- WinExec, ShellExecute,CreateProcess 区别
- ShellExecute, WinExec, CreateProcess区别
- ShellExecute, WinExec, CreateProcess区别
- ShellExecute, WinExec, CreateProcess区别
- ShellExecute, WinExec, CreateProcess区别
- ShellExecute, WinExec, CreateProcess区别
- WinExec, ShellExecute,CreateProcess 区别
- ShellExecute, WinExec, CreateProcess区别
- ShellExecute, WinExec, CreateProcess区别
- ShellExecute, WinExec, CreateProcess区别
- system,WinExec, ShellExecute,CreateProcess 区别
- ShellExecute, WinExec, CreateProcess区别
- ShellExecute, WinExec, CreateProcess的使用
- WinExec, ShellExecute, CreateProcess三个函数的区别和联系
- shell的条件测试
- 五种常见的PHP设计模式
- javadoc的使用及eclipse生成
- 内核watchdog
- VSTO调试
- 日常工作问题总结(三十二)shellExecute、shellExecuteEx、WinExec、CreateProcess的区别
- [译]我面试过的上百个候选者中成功的人总会做的事情
- PKI技术能否保障云计算的安全与可信?
- android 三种定位方式
- shell测试文件状态
- 哇额和为人很热
- eclipse启动tomcat访问不到主页
- YII2 关联查询使用
- sencha touch使用遮罩