views:

56

answers:

4

HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "Shell" returns the shell name, usually Explorer.exe. However, it does not contain the path, or identify a particular executable file.

Enumerating the Task List locates the task Explorer.exe.

But what if the user had ran another, unrelated task called Explorer.exe?

What is the best way to determine that a particular instance of Explorer.exe is actually the shell?

I need to avoid confusion between task(s) which are the shell, and tasks which may not be the shell, but share the same name i.e. Explorer.exe

A: 

You could use Process Explorer to get more details of the process. You would be able to tell by the programs running under each explorer process, the location of the explorer process file, and a couple other things.

Iuvat
Thanks but I need to do this programmatically (I have C++ native or .NET) to identify all the instances of Explorer.exe (or whatever the shell name is) on the system in all sessions which are actual real instances of the Shell.
BillyG
You can still look at location of executable running, etc. problematically to find the answer. Consider adding specific language tags or clarifying your question.
Iuvat
Of course its possible to find the path to the executable. But how to tell whether that executable is the shell? As far as I can tell, Windows would look down its path list to try to find Explorer.exe because no path is specified in registry. But that seems to be a very long way around to guess which exe Windows *probably* used for the shell.
BillyG
Check the precess ID of something like the start bar or a currently open exporter window??
Iuvat
Thanks but ... if there are multiple logged-in users on the box, there will be multiple start bars and explorer windows
BillyG
A: 

Maybe you could use the command line utility tasklist as follows:

tasklist /FI "imagename eq explorer.exe" /FI "session eq 1" /FI "sessionname eq Console"
orvado
A: 

Don't look for Explorer.exe, look for the full path of the shell, which should be C:\Windows\Explorer.exe.

Billy ONeal
The problem is that the Shell entry in the registry (see top of OP) only contains Explorer.exe
BillyG
@BillyG: The complete location is resolved using the PATH environment variable. You can resolve the correct location yourself (using, for example, the PathFindOnPath function). You can also probably just use %WINDIR%\Explorer.exe, because few people are going to completely replace the shell.
Billy ONeal
A: 

I don't think there is a foolproof method; the best you could do is emulate what CreateProcess does:

If the file name does not contain a directory path, the system searches for the executable file in the following sequence:

  1. The directory from which the application loaded.
  2. The current directory for the parent process.
  3. The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
  4. The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.
  5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
  6. The directories that are listed in the PATH environment variable.
Luke