无法“安全删除”调用 Process.Start 并终止后的闪存驱动器
我想从闪存驱动器运行以下应用程序,例如 F:\App.exe:
static void Main(string[] args)
{
Process.Start(@"C:\AnotherApp.exe");
}
但是,App.exe 终止后,不可能“安全地”运行删除”驱动器 F: 直到AnotherApp.exe 也终止。使用 Sysinternals Process Monitor 查看进程树时,AnotherApp.exe 进程仍然是 App.exe 的子进程(已终止)。
有没有一种方法可以从闪存驱动器上的应用程序启动进程,而不会阻止其安全删除?
I have a following application I want to run from a flash drive, say F:\App.exe:
static void Main(string[] args)
{
Process.Start(@"C:\AnotherApp.exe");
}
However, after App.exe terminates, it is impossible to "Safely Remove" drive F: until AnotherApp.exe terminates as well. When viewing the process tree using Sysinternals Process Monitor, process AnotherApp.exe is still a child of App.exe (which is terminated).
Is there a way to start a process from an application on a flash drive, that would not block its safe removal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Process.Start 始终生成一个进程作为启动应用程序的子进程。
即使您终止父级,子级仍然是该父级的孤儿,并且我认为它仍然保留父级句柄。
编辑:
好的,我明白了。
问题是子进程以
F:\
作为当前目录启动。您可以通过
P/ 使用
,并设置不同的起始目录(我已经测试过它并且它有效)。CreatePocess()
创建进程调用示例如下:
http://pastebin.com/QsMqejS5
Process.Start
always spawns a process as child of the lauching application.Even if you terminate the parent, the child will still be an orphan of that one, and I think it still holds the parent handles.
EDIT:
OK, I got it.
The problem is that the child process is started with
F:\
as its current directory.You can create process using
CreatePocess()
throughP/Invoke
, and the set a different starting directory (I've tested it and it works).Example here:
http://pastebin.com/QsMqejS5