开发者

Unable to "Safely Remove" flash drive after calling Process.Start and terminating

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?


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() through P/Invoke, and the set a different starting directory (I've tested it and it works).

Example here:

http://pastebin.com/QsMqejS5

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜