CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2008
    Posts
    7

    How to close 32 bit and 64 bit programs in C#

    this code works to close 64 bit programs after i pick the program.
    private void btnSleep_Click(object sender, System.EventArgs e)
    {
    string processName = ExtractProcessName(ofdBrowse1.FileName);

    foreach(Process p in Process.GetProcesses())
    {
    if(0 == String.Compare(processName, p.ProcessName, true))
    {
    p.CloseMainWindow();
    }
    }
    }

    private string ExtractProcessName(string fileName)
    {
    string processName = fileName;

    int index = processName.LastIndexOf("\\");

    if(-1 != index)
    {
    processName = processName.Substring(index + 1, processName.Length - index - 1);
    }

    processName = processName.ToUpper();
    processName = processName.Replace(".EXE", "");

    return processName;
    }

    How can I get this code to close both 32 bit and 64 bit programs?

  2. #2
    Join Date
    Mar 2011
    Location
    London
    Posts
    54

    Re: How to close 32 bit and 64 bit programs in C#

    This should work for 32bit programs too. It looks like you're navigating to the executable in your file system.

    32 bit apps on a 64bit OS are normally stored in C:\Program Files (x86) instead of c:\Program Files

    Does that help?

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: How to close 32 bit and 64 bit programs in C#

    Have you tried it and it doesn't work, or are you just asking? Because it should work. You can only try to add call to Proces.Close().
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  4. #4
    Join Date
    Mar 2011
    Location
    London
    Posts
    54

    Re: How to close 32 bit and 64 bit programs in C#

    I ran your program and closed both 64bit and 32bit Internet Explorer. I'm running 64bit Windows 7.

  5. #5
    Join Date
    Oct 2008
    Posts
    7

    Re: How to close 32 bit and 64 bit programs in C#

    I can close windows media player (64) but but can't close blaze media pro(86)

  6. #6
    Join Date
    Oct 2008
    Posts
    7

    Re: How to close 32 bit and 64 bit programs in C#

    Ok I seem to be able to close 32 bit programs that don't require me to say yes to start the program

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured