{"record":{"id":"07f3d3d768552aee","repo":"netchx/netch","slug":"copy-netfilter2-sys-failed-e-message","errorCode":null,"errorMessage":"Copy netfilter2.sys failed\n{e.Message}","messagePattern":"Copy netfilter2\\.sys failed\n(.+?)","errorType":"exception","errorClass":"MessageException","httpStatus":null,"severity":"error","filePath":"Netch/Controllers/NFController.cs","lineNumber":211,"sourceCode":"    ///     安装 NF 驱动\n    /// </summary>\n    /// <returns>驱动是否安装成功</returns>\n    private static void InstallDriver()\n    {\n        Log.Information(\"Install netfilter2 driver\");\n        Global.MainForm.StatusText(i18N.Translate(\"Installing netfilter2 driver\"));\n\n        if (!File.Exists(Constants.NFDriver))\n            throw new MessageException(i18N.Translate(\"builtin driver files missing, can't install NF driver\"));\n\n        try\n        {\n            File.Copy(Constants.NFDriver, SystemDriver);\n        }\n        catch (Exception e)\n        {\n            Log.Error(e, \"Copy netfilter2.sys failed\\n\");\n            throw new MessageException($\"Copy netfilter2.sys failed\\n{e.Message}\");\n        }\n\n        // 注册驱动文件\n        if (Interops.Redirector.aio_register(\"netfilter2\"))\n        {\n            Log.Information(\"Install netfilter2 driver finished\");\n        }\n        else\n        {\n            Log.Error(\"Register netfilter2 failed\");\n        }\n    }\n\n    /// <summary>\n    ///     卸载 NF 驱动\n    /// </summary>\n    /// <returns>是否成功卸载</returns>\n    public static bool UninstallDriver()","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/netchx/netch/blob/9d99eb1c5a2acbf2a34f2600f94242601019a300/Netch/Controllers/NFController.cs#L193-L229","documentation":"Thrown by NFController.InstallDriver when File.Copy(Constants.NFDriver -> %SystemRoot%\\System32\\drivers\\netfilter2.sys) raised an exception. The native file exists (error 12 already passed) but the copy itself failed; e.Message from the IOException/UnauthorizedAccess is appended.","triggerScenarios":"Netch is not running elevated so it cannot write to System32\\drivers; an existing netfilter2.sys is locked because the driver service is still running; antivirus blocks writing a .sys into drivers; disk full; the target path is protected by tamper protection.","commonSituations":"User launched Netch without admin rights; previous driver still loaded and locking the file; EDR/AV preventing driver drops; Controlled Folder Access blocking the write.","solutions":["Relaunch Netch as administrator.","Stop the netfilter2 service first: `sc stop netfilter2` (NFController.UninstallDriver does this — call it or reboot).","Temporarily disable antivirus/Controlled Folder Access for the Netch directory, then retry.","Free disk space on the system drive.","If the file is stubbornly locked, reboot and retry the install before starting any service that loads it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Require elevation and a stopped driver service before attempting the copy.\nif (!HasAdminRights())\n    throw new MessageException(\"Installing the NF driver requires administrator privileges.\");\ntry { new ServiceController(\"netfilter2\").Stop(); } catch { /* not installed */ }","typeGuard":null,"tryCatchPattern":"try { NFController.InstallDriver(); /* internally: File.Copy */ }\ncatch (MessageException ex) when (ex.Message.StartsWith(\"Copy netfilter2.sys failed\"))\n{\n    // ex.Message carries the inner IOException/UnauthorizedAccess detail.\n    SuggestRunAsAdminOrStopService(ex.Message);\n}","preventionTips":["Always run Netch elevated when a driver install is pending.","Stop the netfilter2 service before reinstalling so the file isn't locked.","Add an antivirus/tamper-protection exclusion for System32\\drivers\\netfilter2.sys.","Reboot to release locks if the file refuses to copy."],"tags":["driver","file-system","permissions","redirector"],"backgroundTag":null,"analyzedSha":"9d99eb1c5a2acbf2a34f2600f94242601019a300","analyzedAt":"2026-08-13T14:12:19.105Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}