Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:52:31+00:00 2026-06-04T04:52:31+00:00

Environment – C#, .net 4.0, VS 2010 Hello, I have written a simple shell

  • 0

Environment – C#, .net 4.0, VS 2010

Hello, I have written a simple shell replacement for Windows. The shell is launched automatically when users log in. The normal Windows “explorer.exe” is launched when users exit my shell.

Now, when users exit (and to properly support this) I need to be able to check if “explorer.exe” is running for the current logged-in user. This prevents the code from unnecessarily launching it again, which results in a “Windows Explorer” application window.

I have seen countless examples of how to check and see if a process is running…but none to see if it is running for the current logged-in user.

The code below will check to see if “explorer.exe” is already running and will start it if it isn’t. But there are situations when this code will test positive when it doesn’t need to!

For example, when using fast-user switching…Another user is logged in to the machine and, as a result, “explorer.exe” shows in the process list. But, while “explorer.exe” is running, it is NOT running for the current logged-in user! So when my shell exits, the code tests positive, and “explorer.exe” is not launched. The user is left with a black screen and no shell!

So, how can I mod the code below to test if “explorer.exe” is running for the current logged-in user?

Process[] Processes = Process.GetProcessesByName("explorer");
if (Processes.Length == 0)
{
   string ExplorerShell = string.Format("{0}\\{1}", Environment.GetEnvironmentVariable("WINDIR"), "explorer.exe");
   System.Diagnostics.Process prcExplorerShell = new System.Diagnostics.Process();
   prcExplorerShell.StartInfo.FileName = ExplorerShell;
   prcExplorerShell.StartInfo.UseShellExecute = true;
   prcExplorerShell.Start();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:52:33+00:00Added an answer on June 4, 2026 at 4:52 am

    You could get SessionID from your process and then query Processes and get Explorer instance that have the same SessionID, let’s say that your program is named “NewShell” :

      Process myProc = Process.GetProcesses().FirstOrDefault(pp => pp.ProcessName.StartsWith("NewShell"));
      Process myExplorer = Process.GetProcesses().FirstOrDefault(pp => pp.ProcessName == "explorer" && pp.SessionId == myProc.SessionId);
    
      if (myExplorer == null)
        StartExplorer()
    

    btw. if you use ProcessName.StartsWith("NewShell") instead of ProcessName == "NewShell" then it will work under VS debugger also (it adds vshost to the exe)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Environment: Windows 7 SP1 Visual Studio 2010 Ultimate SP1 .NET 4.0 I have a
Environment: Visual Studio Ultimate 2010 .NET 4.0 Windows XP, Vista and 7 We have
Environment: Windows XP. Visual Studios 2010. Language - C++. I have run into the
Environment: Windows Server 2008 R2 IIS 7.5 .NET 4.0, Integrated Application Pool Oracle Client
[Environment] Windows 7 Ultra VS 2010 Ultra Entity Framework 4.2 Entity Framework Power Tool
Environment: ASP.NET MVC3 C# Say I have some repository (semi-psuedo): public interface IRepository {
Environment : Visual Studio 2010 v10.0.31118.1 SP1, Addins : jetBrain,DXCore,VisualSVN Windows 7 (up to
Environment: Windows XP, Visual Studio 2010, IIS NOT installed. I've developed a WCF service
Environment Mono, PostgreSQL, .Net MVC, Windows I'm try to show all events that occur
Environment: Windows Server 2003 R2 Enterprise 64bit, SP2 .NET framework is supposedly installed (2.0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.