从 NPAPI 插件中启动外部应用程序
我正在尝试弄清楚为什么我编写的 NPAPI 插件(在执行通过 Javascipt 调用触发的操作方面工作正常)无法使用 CreateProcess() 或 ShellExecute() 从通过 Javascript 调用指定的路径启动应用程序。
我似乎可以使用这些方法中的任何一个,并且它们返回成功,即没有错误代码。但该应用程序就是不启动。我尝试修改调用它们时使用的参数,创建新的进程组等,但似乎没有效果。
我知道这可能看起来有点安全风险,但出于我们希望使用它的特定目的,它应该不成问题。
使用Windows XP Pro SP3、Firefox 3.5和以下代码:
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if( CreateProcess( NULL, wFileName, NULL, NULL, FALSE,
CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP,
NULL, NULL, &si, &pi ) )
{
bSuccess = true; // Close process and thread handles.
WaitForSingleObject(pi.hProcess,INFINITE);
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
I am trying to work out why an NPAPI plugin I have written, which works fine in terms of performing operations triggered via Javascipt calls, cannot use CreateProcess() or ShellExecute() to launch an application from a path specified via the Javascript call.
I can seemingly use either of these methods and they return success, i.e. no error code. But the application just does not launch. I have tried modifying the parameters used when calling them, to create new process group etc. But seemingly with no effect.
I know this may seem like a bit of a security risk, but for the very specific purpose we wish to use it for it shouldn't be a problem.
Using Windows XP Pro SP3, Firefox 3.5 and the following code:
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if( CreateProcess( NULL, wFileName, NULL, NULL, FALSE,
CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP,
NULL, NULL, &si, &pi ) )
{
bSuccess = true; // Close process and thread handles.
WaitForSingleObject(pi.hProcess,INFINITE);
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有任何代码(片段)可供咀嚼,确实很难给出有价值的提示:
我不明白为什么这在 XP 上不起作用。
您确定 CreateProcess()/ShellExecute() 调用成功吗?
要尝试的事情:
如果传递无效路径,ShellExecute() 调用也会成功吗?
如果您使用硬编码路径(例如 notepad.exe 的路径、不带空格的路径等),会发生什么情况?
使用 ProcessMonitor(以前的 filemon)检查您尝试启动的应用程序的可执行文件是否已被访问。
使用 ProcessMonitor(以前的 filemon)
也许可执行文件无法启动,因为找不到依赖的 DLL。
请记住,工作/当前目录是从插件内启动应用程序时浏览器可执行文件的目录。
因此,可能找不到位于应用程序文件夹中的 DLL。
Without any code (snippet) to chew on it is really hard to give valuable hints:
I don't see why this should not work on XP.
Are you sure that the CreateProcess()/ShellExecute() calls succeed?
Things to try:
Does the ShellExecute() call also succeed if you pass an invalid path?
What happens if you use a hard-coded path (e.g. the path to notepad.exe, a path without spaces, etc.)?
Check with ProcessMonitor (former filemon) if the executable file of the application you are trying to launch is acceessed.
Maybe the executable doesn't launch because a depending DLL is not found.
Keep in mind that the working/current directory is the directory of the browser executable when launching the application from within a plugin.
Therefore DLLs that are located in the application folder might not be found.