How can I create a new instance of explorer.exe by Microsoft Visual C++? - windows-explorer

When I use CreateProcess API, the result is successful, but there is no new instance of explorer.exe, and the old instance just open a folder.
So, How can I create a new instance of explorer.exe by Microsoft Visual C++ ?

Check Explorer.exe Command-Line Options for Windows XP out.
Quote:
The options that you can use with Explorer.exe are /n, /e, /root (plus an object), and /select (plus an object).
Option Function
/n Opens a new single-pane window for the default
selection. This is usually the root of the drive that
Windows is installed on. If the window is already
open, a duplicate opens.
/e Opens Windows Explorer in its default view.
/root, Opens a window view of the specified object.
/select, Opens a window view with the specified folder, file,
or program selected.
Examples
Example 1: Explorer /select,C:\TestDir\TestProg.exe
Opens a window view with TestProg selected.
Example 2: Explorer /e,/root,C:\TestDir\TestProg.exe
Opens Explorer with drive C expanded and TestProg selected.
Example 3: Explorer /root,\TestSvr\TestShare
Opens a window view of the specified share.
Example 4: Explorer /root,\TestSvr\TestShare,select,TestProg.exe
Opens a window view of the specified share with TestProg selected.

Process.Start method

Related

How do I open a given directory or folder in an existing Explorer window?

I'm trying to create a shell command to open a given directory in the Explorer folder that the command is executed from.
I would add it as an entry to the right-click menu in regedit (HKCR\Directory\background\shell), but I can't figure out how to actually make the folder open in the current Explorer instance. (like the "open file location" option).
The open file location feature (COpenFileLocationMenu in shell32) is a shell extension, not a simple static command in the registry. COpenFileLocationMenu also implements IObjectWithSite.
When the IContextMenu::InvokeCommand method in COpenFileLocationMenu is called, it calls IUnknown_QueryService(..., SID_SInPlaceBrowser, IShellBrowser) on its site so it can navigate the Explorer window with IShellBrowser.
Background menu items receive the folder location in IShellExtInit::Initialize and normal menu items can use IShellBrowser::QueryActiveShellView to get the view and then find the current location...
If you don't want to write a shell extension then you have to settle for the scriptable ShellWindows object but you would have to do some guessing to find the correct window, perhaps by PInvoke'ing GetForegroundWindow from Powershell.

Open folder on portable device with batch file

General goal: create a desktop shortcut to a folder buried the file structure of my phone's SD card (connected via USB). Note, this is on a work computer, so I can't do anything to crazy.
I tried using normal shortcuts to no avail, so I decided to try using a batch if I can't use a shortcut. If using a shortcut is possible or there is a better option than a batch let me know.
Specific question: How can I open a folder using a batch file? I can manually open explorer, paste the address into the bar and go there, so there should be a way to mimic this, but so far my attempts have been unsuccessful.
Attempts:
%SystemRoot%\explorer.exe "Computer\My S4\Phone\Android\data\com.dropbox.android\files\scratch\"
explorer Computer/My S4/Phone/Android/data/com.dropbox.android/files/scratch
start "" "Computer\My S4\Phone\Android\data\com.dropbox.android\files\scratch\"
start Computer\My S4\Phone\Android\data\com.dropbox.android\files\scratch
This is an addition to Andry's answer:
It can be very complicated to get the whole path to an MTP folder like
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_03de&pid_21e7&mi_00#6&a5ebb37&1&0000#{6ac27878-a6fc-2155-ea85-f98f491d4f33}\{E4FC4EA5-FFFF-FFFF-0000-000000000000}
To get the path do the following:
In Windows Explorer select the folder on the MTP device you want to get the path of.
Open it's context menu and select Copy
Open in Explorer a folder on your PC, open the context menu on a free area and select Paste Shortcut
Now we need a too that can read .lnk files. I have used the tool LECmd. Execute LECmd.exe -f <path to the .lnk file created in step 3>.
You will get a lot of content printed to the console. The interesting part is the Parsing Path next to the end.
In my case it was ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_03de&pid_21e7&mi_00#6&a5ebb37&1&0000#{6ac27878-a6fc-2155-ea85-f98f491d4f33}\SID-{10001,,21003612160}\{E4FC4EA5-FFFF-FFFF-0000-000000000000}
Now we are close, unfortunately the path shown above can not be used because it contains an invalid part: \SID-{10001,,21003612160}. Remove that part and you can open the explorer in that MTP folder using
start "" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_03de&pid_21e7&mi_00#6&a5ebb37&1&0000#{6ac27878-a6fc-2155-ea85-f98f491d4f33}\{E4FC4EA5-FFFF-FFFF-0000-000000000000}"
There is a way to open an MTP device folder directly in the Windows Explorer window on Windows 7 x64.
Here is steps:
Open Windows Explorer with the My Computer folder, for example:
start "" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
start "" "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
explorer "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
explorer "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
The complete list of GUIDs you can find on the internet, for example: https://www.tenforums.com/tutorials/3123-clsid-key-guid-shortcuts-list-windows-10-a.html
Attach the MTP device and enable File Transfer mode in the device. It must be shown in the My Computer window as a portable device entry.
Drag and Drop the MTP device entry icon to the Desktop.
Open any notepad, for the instance, Windows notepad: Win+R -> notepad
Drag and drop the desktop icon into notepad window.
At the end of the notepad text would be something like:
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_0e8d&pid_201d&mi_00#7&1084e14&0&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33} (spaces removed).
You can cleanup the spaces between characters by copy the string into another instance of the notepad and replace them through the Ctrl+H to nothing.
Now you can open the MTP device folder directly:
start "" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_0e8d&pid_201d&mi_00#7&1084e14&0&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33}\<your-local-path-to-folder>"
There is a wait timeout, so the Windows Explorer window might not open immediately.
To generate a shortcut to target folder you can use make_shortcut.vbs script from here: https://github.com/andry81/contools/tree/HEAD/Scripts/Tools/ToolAdaptors/vbs/
For example:
>
make_shortcut.vbs myphonecamera.lnk "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_0e8d&pid_201d&mi_00#7&1084e14&0&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33}\SD-card Samsung\DCIM\Camera
Now you can click myphonecamera.lnk to open the folder or use the Windows Explorer:
>
explorer myphonecamera.lnk
Instead of using Computer which is not a device name, try to use \\?\ or \\.\ which both refer to the local computer.

How to locate a file in windows explorer

I have a application to list all music files in user machine, a "Explorer" button is using to quickly open Windows Explorer and highlight the file in Windows Explorer. I tried ShellExecute, but it doesn't work, the API will launch associate application. Any Windows API can do that? Thanks in advance.
You can simply start explorer.exe with the /select argument, as detailed in this Knowledge Base article:
Explorer /select,C:\TestDir\TestApp.exe
You can create an IE instance and navigate to your folder, then query the IShellBrowser service from the top level browser service and get the active view's IShellView interface. Use IShellView::SelectItem to select items.
Remember to call IWebBrowser::Quit when you don't need the explorer window.
This method can not get around Windows Vista's User Interface Privilege Isolation. If the folder is opened in a process with a different integrity level, a broker IE extension is needed to continue the automation.

How to implement 'open file location' behaviour programmatically (c++ builder)

In Windows Media Player you can right click on a music file and click 'open file location' and it opens an explorer window with the file selected.
I want to be able to do this in applications. So given a filename (as an ansi string) I want to be able to go to the file in a new explorer window.
Try launching explorer.exe with option /select,<selected file path>. Something like:
explorer /n, /select,c:\windows\notepad.exe
It should open new explorer window with c:\windows folder open and notepad.exe selected.
You should use the ShellExecute() function. Something like this should work:
ShellExecute(handle, "explore", #"C:\WINDOWS", NULL, NULL, SW_SHOWNORMAL);
It's a Win2 FAQ for more than 16 years (!)
Search on Google Groups before posting a so basic question where the C code has been posted 25000 times...

Windows Explorer "Command Prompt Here" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I frequently find myself with a folder open in Windows, wishing to have a command prompt open with the same working directory.
I am aware of Power Toys "Command Prompt", but that only works as a context menu item on the folder, and not from inside the folder if you are already there. I know you can navigate to the parent directory, and use it from there, but if the parent has thousands of directories in it, this is not so convenient. I have tried some home-brewed batch files associated with folder actions in explorer, but those suffer from similar problems.
So, what is the quickest way to open a command prompt with a working directory of the current windows explorer folder?
My current approach: (horrible)
Alt - D, Ctrl - C (copy path)
Win - R, "cmd", Enter (start command prompt)
"cd", Space (start a change directory command)
Alt - Space, e, p (paste directory)
Enter (execute change directory)
I know there is something better! What is it?
Hold Shift while Right-Clicking a blank space in the desired folder to bring up a more verbose context menu. One of the options is Open Command Window Here. This works in Windows Vista, 7, 8, and 10. Since Windows 10 Creators Update, the option has been replaced with Open PowerShell Here. However, there are ways to enable Open Command Window Here again.
Just type "cmd" to location bar, that's it. It will start a new command prompt in current path.
This solution was confirmed to work in Windows XP, Vista, 7, 8 and 10 (including Creators Update).
Keystrokes to move the focus to the location bar:
AltD in English (pointed out by Tim Stewart in the comments)
AltE in German
Inside your current folder, simply press Shift+Alt+F --then--> Enter.
The prompt will appear with your current folder's path set.
Note: That works only in Windows 7 / Vista. What it does is that drops the "File" menu down for you, because the "Shift" key is pressed the option "Open command window here" is enabled and focused as the first available option of "File" menu. Pressing enter starts the focused option therefor the command window.
Edit:
In case you are in a folder and you already selected some of its contents (file/folder) this wont work. In that case Click on the empty area inside the folder to deselect any previously selected files and repeat.
Edit2:
Another way you can open terminal in current directory is to type cmd on file browser navigation bar where the path of current folder is written.
In order to focus with your keyboard on the navigation bar Ctrl+L. Then you can type cmd and hit Enter
Right-click the title-bar icon of the Explorer window. You'll get the current folder's context menu, where you'll find the "command window here" item.
(Note that to see that menu item, you need to have the corresponding "power toy" installed, or you can create the right registry keys yourself to add that item to folders' context menus.)
As a very quick solution I can give you this. I tested this on Windows 8.1
1- Find File and Right Click on Command Prompt on File Explorer and then add command prompt to your Quick Access Toolbar:
2- After adding it you can access the folder from here:
That will open a command prompt in there for you.
On vista and windows 7:
Alt+d -> it will put focus on the address bar of the explorer window
and then, type the name of any program you would launch using WIN+r
hit Enter
The program will start with its current directory set to that of the explorer instance.
e.g.:python, ghci, powershell, cmd, etc...
For Windows vista and Windows 7 ,to open the command prompt
1) go to folder you want to work
2)In address bar type- cmd
press enter
it will open the command prompt for that location
You can edit the registry to add the Command Prompt item to the context menu. Here are a couple of .reg files that I use.
Cmdhere.reg - for WinNT/2000/XP/Vista/7:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\OpenNew]
#="Command Prompt"
[HKEY_CLASSES_ROOT\Directory\shell\OpenNew\Command]
#="cmd.exe /k cd %1"
[HKEY_CLASSES_ROOT\Drive\shell\OpenNew]
#="Command Prompt"
[HKEY_CLASSES_ROOT\Drive\shell\OpenNew\Command]
#="cmd.exe /k cd %1"
Doshere.reg - for Win9x:
REGEDIT4
[HKEY_CLASSES_ROOT\Directory\shell\OpenNew]
#="MS-DOS Prompt"
[HKEY_CLASSES_ROOT\Directory\shell\OpenNew\Command]
#="command.com /k cd %1"
[HKEY_CLASSES_ROOT\Drive\shell\OpenNew]
#="MS-DOS Prompt"
[HKEY_CLASSES_ROOT\Drive\shell\OpenNew\Command]
#="command.com /k cd %1"
Copy this into an empty text file and change the extension to .reg. Double-clicking on this in Windows Explorer will add these key to the registry.
I use StExBar, a Windows Explorer extension that gives you a command prompt button in explorer along with some other cool features (copy path, copy file name & more).
https://tools.stefankueng.com/StExBar.html
EDIT:
I just found out (been using it for more than a year and did not know this) that Ctrl+M will do it with StExBar. How's that for fast!
Almost the same as yours:
Alt+d, Ctrl+c
Win+r
cmd /K cd , Ctrl+v, ENTER
If that's so bothering, you could try to switch to windows explorer alternative like freecommander which has a toolbar button for that purpose.
I use a lot the "Send To" functionality.
I create my own batch (.bat) files in the shell:sendto folder and send files/folders to them using the context menu (to get there just write 'shell:sendto' in location bar).
I have scripts to perform all sort of things: send files by ftp, launch a php server in the current folder, create folders named with the current date, copy sent path to clipboard, etc.
Sorry, a bit offtopic but useful anyway.
Tried the answer given by Tough Coder in Windows 7 and it works!
Create a shortcut to cmd.exe in %HOMEDRIVE%%HOMEPATH%\Links, open its file properties and change the field 'Start at' to %1 ('Iniciar en' translated from spanish).
Now drag folders to it and you'll see the magic. It works too in all standard Open File dialogs. wow!
ps: those 'strange' tabs above in my picture are because I use Clover. I recommend it!
Use the following in command prompt to open your current location in windows explorer:
C:\your-directory> explorer .

Resources