{"record":{"id":"3e3ab95717c5f182","repo":"ZyperWave/ZyperWinOptimize","slug":"cmd-process-exitcode-error","errorCode":null,"errorMessage":"CMD执行失败，退出码: {process.ExitCode}\n错误信息: {error}","messagePattern":"CMD执行失败，退出码: (.+?)\n错误信息: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ZyperWin++/ZyperWin++/Activate.cs","lineNumber":82,"sourceCode":"                        process.StartInfo.FileName = \"cmd.exe\";\r\n                        process.StartInfo.Arguments = $\"/c \\\"{filePath}\\\"\";\r\n                        process.StartInfo.UseShellExecute = false;\r\n                        process.StartInfo.CreateNoWindow = false; // 设置为false可以看到CMD窗口\r\n                        process.StartInfo.RedirectStandardOutput = true;\r\n                        process.StartInfo.RedirectStandardError = true;\r\n                        process.StartInfo.WorkingDirectory = Path.GetDirectoryName(filePath);\r\n\r\n                        process.Start();\r\n\r\n                        // 读取输出（可选）\r\n                        string output = process.StandardOutput.ReadToEnd();\r\n                        string error = process.StandardError.ReadToEnd();\r\n\r\n                        process.WaitForExit();\r\n\r\n                        if (process.ExitCode != 0)\r\n                        {\r\n                            throw new Exception($\"CMD执行失败，退出码: {process.ExitCode}\\n错误信息: {error}\");\r\n                        }\r\n                    }\r\n                }\r\n                catch (Exception ex)\r\n                {\r\n                    throw new Exception($\"执行CMD文件时出错: {ex.Message}\");\r\n                }\r\n            });\r\n        }\r\n    }\r\n}\r\n","sourceCodeStart":64,"sourceCodeEnd":94,"githubUrl":"https://github.com/ZyperWave/ZyperWinOptimize/blob/d20e78bbd906fa179e4cc9f5107b502da5967aa9/ZyperWin++/ZyperWin++/Activate.cs#L64-L94","documentation":"ExecuteCmdFile runs MAS_AIO_CN.cmd via cmd.exe with redirected output and throws this Exception when the child process exits with a non-zero ExitCode. The message carries the exit code and everything the script wrote to stderr. It indicates the activation script itself failed, not a C# bug.","triggerScenarios":"Clicking the activation button (button1_Click -> ExecuteCmdFile) when MAS_AIO_CN.cmd returns a non-zero exit code: the script's own logic failed, a required service (e.g. sppsvc / Software Protection) is stopped or broken, antivirus blocked the script, or the cmd file is missing/corrupt inside .\\Bin\\.","commonSituations":"Antivirus/Defender quarantining MAS script components; Windows licensing service (sppsvc) disabled by tweakers; running on unsupported Windows edition; incomplete installation where Bin\\ files are blocked or partially extracted (Zone.Identifier blocking downloaded files).","solutions":["Read the 错误信息 in the message to see the script's stderr; fix the underlying issue it reports.","Verify .\\Bin\\MAS_AIO_CN.cmd exists and is not blocked: right-click > Properties > Unblock, or `Unblock-File` the extracted files.","Ensure the Software Protection service (sppsvc) is running: `sc query sppsvc` / `net start sppsvc`.","Temporarily exclude the app folder from antivirus and re-run; many AV products flag MAS scripts.","Re-download a complete copy of ZyperWin++ so the Bin directory is intact."],"exampleFix":"// before: caller loses exit-code detail in a generic wrapper\ncatch (Exception ex) { throw new Exception($\"执行CMD文件时出错: {ex.Message}\"); }\n// after: check prerequisites up front and preserve the exit code\nif (Process.GetProcessesByName(\"sppsvc\").Length == 0 &&\n    ServiceHelper.Start(\"sppsvc\") != 0)\n    throw new Exception(\"sppsvc 未运行且无法启动\");\n// let the original exit-code exception surface unwrapped","handlingStrategy":"try-catch","validationCode":"string cmdFilePath = Path.Combine(Application.StartupPath, \"Bin\", \"MAS_AIO_CN.cmd\");\nif (!File.Exists(cmdFilePath)) { MessageBox.Show(\"缺少 MAS_AIO_CN.cmd\"); return; }\nvar sppsvc = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == \"sppsvc\");\nif (sppsvc == null || sppsvc.Status != ServiceControllerStatus.Running) { MessageBox.Show(\"sppsvc 未运行\"); return; }","typeGuard":null,"tryCatchPattern":"try { await ExecuteCmdFile(cmdFilePath); }\ncatch (Exception ex) when (ex.Message.Contains(\"退出码\"))\n{ MessageBox.Show($\"激活脚本失败：{ex.Message}\\n请检查杀毒软件与 sppsvc 服务。\", \"错误\", MessageBoxButtons.OK, MessageBoxIcon.Error); }","preventionTips":["Ship a verified, unblocked Bin\\ directory with the app.","Pre-check sppsvc status before offering activation.","Document antivirus exclusions for the tool's folder.","Surface the script's stderr verbatim to the user instead of only the exit code."],"tags":["process-exit-code","cmd-script","windows","activation"],"backgroundTag":"command-not-found","analyzedSha":"d20e78bbd906fa179e4cc9f5107b502da5967aa9","analyzedAt":"2026-09-13T15:15:37.168Z","contentChangedAt":"2026-09-13T15:15:37.168Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}