问题
my program runs on the background and I wanted it, given that I have explorer.exe windows open for example in My Music folder to select(Not open) "test.txt". But when I run my code(see below) It opens a new window with the file selected. I want it to just select the file, on the window that's already open.
Code:
string pathname = "c:\DocTest\Test.txt";
ProcessStartInfo l_psi = new ProcessStartInfo();
l_psi.Filename = "Explorer";
l_psi.Arguments = string.Format(@"/select, " + @ "" + pathname);
l_psi.UseShellExecute=true;
Process l_newProcess = new Process();
l.newProcess.StartInfo = l_psi;
l_newProcess.Start();
Please remember the two points:
-I don't want it to open the file, only to select it on a folder
-I don't want it to open a new explorer window, just use the one that's already open
Thanks for reading :)
回答1:
As found on Microsoft Support
Syntax
EXPLORER.EXE [/n][/e][,/root,][[,/select],] Switches
/n: Opens a new window in single-paned (My Computer) view for each item selected, even if the new window duplicates a window that is already open.
/e: Uses Windows Explorer view. Windows Explorer view is most similar to File Manager in Windows version 3.x. Note that the default view is Open view.
/root,: Specifies the root level of the specified view. The default is to use the normal namespace root (the desktop). Whatever is specified is the root for the display.
/select,: Specifies the folder to receive the initial focus. If "/select" is used, the parent folder is opened and the specified object is selected.
There is no mention of reusing an open Explorer, so it might not be possible.
来源:https://stackoverflow.com/questions/28763353/make-current-explorer-exe-window-select-a-file