ZyperWave/ZyperWinOptimize · error · Exception

CMD执行失败,退出码: 错误信息

Error message

CMD执行失败,退出码: {process.ExitCode}
错误信息: {error}

What it means

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.

Solutions

  1. Read the 错误信息 in the message to see the script's stderr; fix the underlying issue it reports.
  2. Verify .\Bin\MAS_AIO_CN.cmd exists and is not blocked: right-click > Properties > Unblock, or `Unblock-File` the extracted files.
  3. Ensure the Software Protection service (sppsvc) is running: `sc query sppsvc` / `net start sppsvc`.
  4. Temporarily exclude the app folder from antivirus and re-run; many AV products flag MAS scripts.
  5. Re-download a complete copy of ZyperWin++ so the Bin directory is intact.

Example fix

// before: caller loses exit-code detail in a generic wrapper
catch (Exception ex) { throw new Exception($"执行CMD文件时出错: {ex.Message}"); }
// after: check prerequisites up front and preserve the exit code
if (Process.GetProcessesByName("sppsvc").Length == 0 &&
    ServiceHelper.Start("sppsvc") != 0)
    throw new Exception("sppsvc 未运行且无法启动");
// let the original exit-code exception surface unwrapped
Defensive patterns

Strategy: try-catch

Validate before calling

string cmdFilePath = Path.Combine(Application.StartupPath, "Bin", "MAS_AIO_CN.cmd");
if (!File.Exists(cmdFilePath)) { MessageBox.Show("缺少 MAS_AIO_CN.cmd"); return; }
var sppsvc = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == "sppsvc");
if (sppsvc == null || sppsvc.Status != ServiceControllerStatus.Running) { MessageBox.Show("sppsvc 未运行"); return; }

Try / catch

try { await ExecuteCmdFile(cmdFilePath); }
catch (Exception ex) when (ex.Message.Contains("退出码"))
{ MessageBox.Show($"激活脚本失败:{ex.Message}\n请检查杀毒软件与 sppsvc 服务。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); }

Prevention

When it happens

Trigger: 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\.

Common situations: 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).

Related errors


AI-assisted analysis of ZyperWave/ZyperWinOptimize@d20e78bbd9 (2026-09-13). Data as JSON: /api/errors/3e3ab95717c5f182. Report an issue: GitHub.

Appendix: source

Thrown at ZyperWin++/ZyperWin++/Activate.cs:82

                        process.StartInfo.FileName = "cmd.exe";
                        process.StartInfo.Arguments = $"/c \"{filePath}\"";
                        process.StartInfo.UseShellExecute = false;
                        process.StartInfo.CreateNoWindow = false; // 设置为false可以看到CMD窗口
                        process.StartInfo.RedirectStandardOutput = true;
                        process.StartInfo.RedirectStandardError = true;
                        process.StartInfo.WorkingDirectory = Path.GetDirectoryName(filePath);

                        process.Start();

                        // 读取输出(可选)
                        string output = process.StandardOutput.ReadToEnd();
                        string error = process.StandardError.ReadToEnd();

                        process.WaitForExit();

                        if (process.ExitCode != 0)
                        {
                            throw new Exception($"CMD执行失败,退出码: {process.ExitCode}\n错误信息: {error}");
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception($"执行CMD文件时出错: {ex.Message}");
                }
            });
        }
    }
}

View on GitHub (pinned to d20e78bbd9)