Hi Guys

This has been going on for a while but now I have finally decided to do something about it.

A few weeks ago I compiled a small C program from a book I was reading.
It compiled fine but I wanted to make a slight change to the code and instead of compiling the new code and calling it a different name I tried to delete the original exe (calculator.exe) so I could simply make a new one. But when I try to delete/copy or move the exe "Cannot delete calculator: it is being used by another person or program" I checked my running processes to see if for some strange reason the program was running in the background but nothing and the exe has been sitting on my desktop ever since and its annoying.

Does anyone know what I can do to remove this annoying exe please and does anyone know why this has happened.


Many thanks

HLA91

P.S here is the code

#include <stdio.h>

char line[100];/* Line of text from input*/
int result; /* This shpws the current result of calculation*/
char operator;/*Operator teh user specified*/
int value;/* Value specified after the operator*/
char enter; 

int main ()
{
    printf("H Calculator, for help/license press h, to quit press q\n");
    printf("\n");
    result = 0;
    /* loop forever or until break reached*/
    while (1) {
          printf("\n");
          printf("Enter calculation: \n");
          printf("\n");
          printf("Result: %d\n", result);
          printf(" \n ");
          
          fgets(line, sizeof(line), stdin);
          sscanf(line, "%c %d", &operator, &value);
          
          if((operator == 'q') || (operator == 'Q'))
          break;
          
          switch (operator) {
          
          case '+':
                       result += value;
                       break;
                       case '-': 
                              result -= value;
                              break;
                               case '*':
                              result *= value;
                              break;
                              case 'h':
                                     printf("\tH Calculator\n");
                                     printf("V 1.1\n");
                                     printf("Written by Harry Angell, to use calc simply\n");
                                     printf("Enter the operator followed by the number,eg: +5\n");
                                     printf("\n");
                                     printf("Press return");
                                     
                                     fgets(line, sizeof(line), stdin);
                                     sscanf(line, "%c" , &enter);
                                                                                
    
                                     printf("\n");
                                     printf("\n");
                                     break;
                              case '/':
                              if (value == 0) {
                                        printf("Error: Divide by zero\n");
                                        printf("   operation ignored\n");
                                        } else
                                          result /= value;
                                          break;
                                           default:
                                                 printf("Unknown operator %c\n", operator);
                                                 break;
                                          }
                                        }
                              return (0);
}

Dani AI

Generated

Windows is refusing to remove an EXE because some process or service still has a handle on that file. That handle can come from a running instance of the program, a shell extension (thumbnail/preview), an indexing service, a debugger, or a remote/open-file session. Identifying which process holds the handle is the safest first step before killing anything.

Use Resource Monitor (resmon) to search for handles:

  • Run resmon.exe, go to the CPU tab, expand "Associated Handles", type the EXE name (for example calculator.exe) into the search box and note the owning process.
  • If you find the process, close it from Task Manager or force it with taskkill.

Example commands:

tasklist /FI "IMAGENAME eq calculator.exe"
taskkill /IM calculator.exe /F

If Resource Monitor finds nothing, a more powerful handle search tool is recommended (as suggested). Those tools can show kernel/hidden handles that resmon misses. If a handle still can't be found but the file deletes in a clean environment, that points to a shell/Explorer extension or a startup process as the culprit. Restarting Explorer can be a quick test—end explorer.exe and restart it—rather than rebooting the whole machine.

If the file resides on a shared machine, the message "being used by another person" can be literal: check Computer Management -> Shared Folders -> Open Files, or run openfiles /query (run elevated) to see remote open handles.

Be cautious killing processes—only terminate processes you recognize. To avoid future friction, consider compiling to a new filename during active development (or use a build script that stops/runs the program as part of the cycle). This workflow avoids having to delete an executable that the system still believes is in use.

Recommended Answers

All 8 Replies

I've seen similar problems with Windows XP and earlier versions, and the only way I could resolve the problem was to reboot the computer. I'm using Vista Home now and have not had that problem with this version of Windows.

reboot into safe mode and delete it.

Get process explorer from www.sysinternals.com. One of the many useful features it has is a search tool to find out who's using a file.
It would be the first step to finding out a real answer than just "*shrug* reboot"

Don't forget Dev-C++:

But I doubt that's the problem, if Ancient Dragon encountered the same issue.

Dev-C++ uses MinGW.

And AD only said he has seen the problem, not that he tried compiling OPs code.

The problem likely stems from the 16-bit executable trying to do something in a way that XP doesn't like. It is picky about stuff like that. I've re-written old programs to compile with a modern compiler just so they would run properly.

What it sounds like is that the program is not terminating properly, and the DOS emulator (that comes with Windows to run 16-bit applications) is snagging it in memory because of that.

I could be totally wrong. Let me give it a compile and see what happens...

[EDIT] It behaves properly for me on XP using GCC 4.x.

Another hint: check if an antivirus program is running on the computer. If it is, turn it off to see if that fixes the problem. I've seen Norton Antivirus have some problems with some valid programs. Turned off Norton and the problems went away. Of course you want to turn it back on before accessing the web.

I am using Dev C++ and this has never happened before, only with that specific code. I got rid of it by going into safe mode, I dont have norton, I use avast and comodo pro firewall. Thanks for help guys I know what to do next time IF this ever happens again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.