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

Sidebar

Ask A Question

Stats

  • Questions 280k
  • Answers 280k
  • 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
  • Editorial Team
    Editorial Team added an answer SELECT SUM(row_count) FROM sys.dm_db_partition_stats WHERE index_id IN (0,1) AND OBJECTPROPERTY([object_id],… May 13, 2026 at 3:34 pm
  • Editorial Team
    Editorial Team added an answer Try the following in your view, where the login button… May 13, 2026 at 3:34 pm
  • Editorial Team
    Editorial Team added an answer A data-reader is a hose of data. It becomes "empty"… May 13, 2026 at 3:34 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form

Trending Tags

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

Top Members

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.