[英]Waiting for ShellExecuteEx (Setting access rights on Windows process)
I'm using the ShellExecuteEx
function in a C++ program to launch an Uninstall.lnk file. 我在C ++程序中使用
ShellExecuteEx
函数来启动Uninstall.lnk文件。 In my program, I'd like to wait for the uninstaller to finish. 在我的程序中,我想等待卸载程序完成。 My first attempt was to set the
SEE_MASK_NOCLOSEPROCESS
flag in the SHELLEXECUTEINFO
structure and then call WaitForSingleObject
on the hProcess
handle available in the SHELLEXECUTEINFO
structure passed to ShellExecuteEx
, but that still seemed to return way too early. 我的第一次尝试是在
SHELLEXECUTEINFO
结构中设置SEE_MASK_NOCLOSEPROCESS
标志,然后在传递给ShellExecuteEx
的SHELLEXECUTEINFO
结构中的hProcess
句柄上调用WaitForSingleObject
,但这似乎仍然过早地返回。
My current suspicion is that this is because the process launched by ShellExecuteEx (does it launch a new shell?) creates new child processes, but doesn't wait for them. 我当前的怀疑是,这是因为ShellExecuteEx启动的进程(它是否启动了一个新的shell?)会创建新的子进程,但不会等待它们。 So I'm trying to create a "wait for my child process and all the children it launches" function.
因此,我正在尝试创建一个“等待我的子进程及其启动的所有子进程”功能。 To do so, I'm trying to use job objects.
为此,我正在尝试使用作业对象。
I created a job object using CreateJobObject
, assigned the process handle returned by ShellExecuteEx
to the job and then attempted to wait for the job object. 我使用
CreateJobObject
创建了一个作业对象,将ShellExecuteEx
返回的进程句柄分配给作业,然后尝试等待作业对象。 Unfortunately assigning the process to the job failed, and I think this is due to insufficient access rights. 不幸的是,将进程分配给作业失败了,我认为这是由于访问权限不足。
Does anybody know how to set the PROCESS_SET_QUOTA and PROCESS_TERMINATE access rights (which are required for AssignProcessToJobObject
to succeed, according to the MSDN) on a process handle, or another way to wait for the process launched by ShellExecuteEx to finish? 有没有人知道如何在进程句柄上设置PROCESS_SET_QUOTA和PROCESS_TERMINATE访问权限(
AssignProcessToJobObject
需要成功,根据MSDN),或者等待ShellExecuteEx启动的进程完成的另一种方法?
UPDATE: I should point out that I'm also launching other applications, not just
Uninstall.lnk
. 更新:我应该指出,我也在推出其他应用程序,而不仅仅是
Uninstall.lnk
。 One of them is eg a ClickOnce application, which is effectively a simple XML file with the file extension .application
. 其中一个是例如ClickOnce应用程序,它实际上是一个文件扩展名为
.application
的简单XML文件。
Vista uses job objects for launching links. Vista使用作业对象来启动链接。 Therefor the process you try to assign to another job object might already be assigned.
因此,您可能已经分配了尝试分配给另一个作业对象的进程。
See: this question 见: 这个问题
Why not to execute target file instead of openning Uninstall.lnk
? 为什么不执行目标文件而不是打开
Uninstall.lnk
? You could use IShellLink
to get shortcut target. 您可以使用
IShellLink
获取快捷方式目标。 Then you'll be able to execute target file via ShellExecuteEx using SEE_MASK_NOCLOSEPROCESS
flag. 然后,您将能够使用
SEE_MASK_NOCLOSEPROCESS
标志通过ShellExecuteEx执行目标文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.