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 6962289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:38:29+00:00 2026-05-27T15:38:29+00:00

As part of an application, I’ve added a shortcut bar for relevantly used programs.

  • 0

As part of an application, I’ve added a shortcut bar for relevantly used programs. I have it set up to check if the application is open already, and if it is to switch to it instead of opening another instance. This works fine for programs like calc and notepad, but all the MS Office programs open another instance no matter what, and I’d like them not to.

Office Button

    private void wordButton_Click(object sender, RoutedEventArgs e)
    {            
        try
        {
            SwitchToProcess("winword.exe", "C:\\Program Files (x86)\\Microsoft Office\\Office14\\winword.exe");
        }
        catch (Win32Exception)
        {
            try
            {
                SwitchToProcess("winword.exe", "C:\\Program Files\\Microsoft Office\\Office14\\winword.exe");
            }
            catch (Win32Exception)
            {
            }
        }
    }

Notepad Button

    private void notepadLink_Click(object sender, RoutedEventArgs e)
    {
        SwitchToProcess("notepad.exe");
    }

Methods

private void SwitchToProcess(string name)
    {
        Process[] procs = Process.GetProcesses();
        if (procs.Length != 0)
        {
            for (int i = 0; i < procs.Length; i++)
            {
                try
                {
                    if (procs[i].MainModule.ModuleName == name)
                    {
                        IntPtr hwnd = procs[i].MainWindowHandle;
                        ShowWindowAsync(hwnd, SW_RESTORE);
                        SetForegroundWindow(hwnd);
                        return;
                    }
                }
                catch
                {

                }
            }
        }
        else
        {
            MessageBox.Show("No process running");
            return;
        }
        launchApp.StartInfo.FileName = name;
        launchApp.Start();
    }

    private void SwitchToProcess(string name, string path)
    {
        Process[] procs = Process.GetProcesses();
        if (procs.Length != 0)
        {
            for (int i = 0; i < procs.Length; i++)
            {
                try
                {
                    if (procs[i].MainModule.ModuleName == name)
                    {
                        IntPtr hwnd = procs[i].MainWindowHandle;
                        ShowWindowAsync(hwnd, SW_RESTORE);
                        SetForegroundWindow(hwnd);
                        return;
                    }
                }
                catch
                {

                }
            }
        }
        else
        {
            MessageBox.Show("No process running");
            return;
        }
        launchApp.StartInfo.FileName = path;
        launchApp.Start();
    }

The reason for the two different directories in the Office button is a simple way of ensuring that x86/x64 install locations don’t cause a problem. The computers I’m developing this for have the registry locked out, so I can’t check which one is correct.

  • 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-05-27T15:38:30+00:00Added an answer on May 27, 2026 at 3:38 pm

    Ok, so after digging a little deeper into Google, I finally figured out the problem. I had the program targeted for an x86 processor, and am running it on x64. Switched the target to AnyCPU and it works perfectly. Apparently it was catching an error of Only part of a ReadProcessMemory or WriteProcessMemory request was completed, but since I had the try-catch block in there it wasn’t displaying the error until I used StepInto repeatedly on the 77-item processor array. Thanks everyone for the help though.

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

Sidebar

Related Questions

For part of my application I have a need to create an image of
As part of my application requirements, I have a limit of 30 characters for
We have a part of an application where, say, 20% of the time it
I am developing client part of web application. So i have some controls like
I have a part of an application that loops through a return of a
In part of our application we have the ability to search for music. The
Part of my application maps resources stored in a number of locations onto web
Part of my application depends on JavaMail, moving arranging messages etc. Is it possible
Part of an application I'm writing allows for users to upload images which I
A part of the application that I am working on is a legacy Vb6

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.