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

  • Home
  • SEARCH
  • 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 43083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:26:21+00:00 2026-05-10T15:26:21+00:00

Here’s my issue: I need to close a process, already running, from a C#

  • 0

Here’s my issue: I need to close a process, already running, from a C# program. The problem is that the process now runs as an icon (minimized to taskbar), and unless the user opens it at least once (which will never happen on unattended machines), it’ll never have a main window.

The other requirement that I have is that the application be closed not killed. I need it to write it’s memory buffers to disk – and killing it causes data loss.

Here’s what I tried so far:

        foreach (Process proc in Process.GetProcesses())         {             if (proc.ProcessName.ToLower().StartsWith('myapp'))             {                 if (proc.MainWindowHandle.ToInt32() != 0)                 {                     proc.CloseMainWindow();                     proc.Close();                     //proc.Kill();  <--- not good!                 }             }         } 

I’ve added the if clause, after discovering that MainWindowHandle == 0 when the window was minimized. Removing the if doesn’t help. Neither the CloseMainWindow() nor the Close() work. The Kill() does, but as mentioned above – it’s not what I need.

Any idea would be accepted, including the use of arcane Win32 API functions 🙂

  • 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. 2026-05-10T15:26:21+00:00Added an answer on May 10, 2026 at 3:26 pm

    Here are some answers and clarifications:

    rpetrich: Tried your method before and the problem is, I don’t know the window name, it differs from user to user, version to version – just the exe name remains constant. All I have is the process name. And as you can see in the code above the MainWindowHandle of the process is 0.

    Roger: Yes, I did mean the taskbar notification area – thanks for the clarification. I NEED to call PostQuitMessage. I just don’t know how, given a processs only, and not a Window.

    Craig: I’d be glad to explain the situation: the application has a command line interface, allowing you to specify parameters that dictate what it would do and where will it save the results. But once it’s running, the only way to stop it and get the results is right-click it in the tray notification are and select ‘exit’.

    Now my users want to script/batch the app. They had absolutely no problem starting it from a batch (just specify the exe name and and a bunch of flags) but then got stuck with a running process. Assuming no one will change the process to provide an API to stop it while running (it’s quite old), I need a way to artificially close it.

    Similarly, on unattended computers, the script to start the process can be started by a task scheduling or operations control program, but there’s no way to shut the process down.

    Hope that clarifies my situation, and again, thanks everyone who’s trying to help!

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

Related Questions

No related questions found

Sidebar

Ask A Question

Stats

  • Questions 58k
  • Answers 58k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer SQL*Net message from client means the time taken by oracle… May 11, 2026 at 8:35 am
  • added an answer Hard to say. I'd agree, but perhaps there is something… May 11, 2026 at 8:35 am
  • added an answer Well I've found out how to do this: var item… May 11, 2026 at 8:35 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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.