You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 10命令行运行C程序遇“Access is denied”且.exe消失求助

Hey, sorry to hear you're stuck with this annoying issue—let's walk through some common fixes to get your compiled exe running properly again.

Troubleshooting & Fixes

1. Check Folder Permissions

  • First off, make sure your source code and the generated exe aren't stored in a system-protected directory like C:\Windows or C:\Program Files. Windows restricts regular users from executing/modifying files in these folders, which can lead to access denials or even auto-deletion of your exe.
  • Right-click the folder holding your files, go to Properties > Security, and verify your user account has at least Read & Write and Execute permissions. If not, click Edit to add these permissions for your account.

2. Rule Out Antivirus/Security Software Interception

  • Most antivirus tools (including Windows Defender) flag newly compiled, unrecognized exes as suspicious, often blocking execution or deleting the file entirely.
  • Temporarily disable real-time protection to test: Open Windows Security > Virus & Threat Protection > Manage Settings > Toggle off Real-time protection (remember to turn it back on after testing). If the exe runs normally after this, add your project folder to your antivirus's exclusion list.

3. Verify Compilation Command & Test a Minimal Program

  • Double-check your compile command is standard, like:
    gcc your-source-file.c -o your-executable.exe
    
    Avoid any unusual flags that might be causing unexpected behavior.
  • Test with a super simple program to rule out issues in your original code:
    #include <stdio.h>
    int main() {
        printf("Hello World!\n");
        return 0;
    }
    
    If this runs fine, the problem is likely in your original code (e.g., illegal memory access, attempts to modify system files that trigger security blocks).

4. Run Command Prompt as Administrator

  • Sometimes regular CMD permissions aren't enough to execute certain programs. Right-click Command Prompt and select Run as administrator, then navigate to your project folder, recompile, and try running the exe again.

5. Check MinGW Version & Environment Variables

  • It's possible your MinGW installation is corrupted, or the environment variables are misconfigured. Try reinstalling MinGW, or verify the gcc path is in your system PATH by running:
    where gcc
    
    If this returns a valid file path, your environment setup is good; if not, add the MinGW bin directory to your system PATH.

内容的提问来源于stack exchange,提问作者Vandana Prabhu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 18:12:39