ZyperWave/ZyperWinOptimize · error · Exception

PowerShell 错误:

Error message

PowerShell 错误: 

What it means

LoadAppListAsync enumerates installed AppX packages by running a Get-AppxPackage PowerShell script. If powershell.exe exits non-zero, it throws "PowerShell 错误: " + stderr. In this app the exception is caught locally and shown as a "加载失败: ..." list item rather than crashing.

Solutions

  1. Check the stderr text after 'PowerShell 错误: ' — it names the real cmdlet/policy failure.
  2. Verify the service: `sc query AppXSvc` and start it if stopped.
  3. Test manually: run `powershell -Command "Get-AppxPackage"` in a console; if it errors on execution policy, adjust or use `-ExecutionPolicy Bypass` in Arguments.
  4. On stripped/Server SKUs where Get-AppxPackage does not exist, treat the empty list as normal instead of an error.
  5. Repair the component store / user profile if the cmdlet reports deployment errors (DISM /Online /Cleanup-Image /RestoreHealth).

Example fix

// before
p.StartInfo.Arguments = $"-Command \"{psScript}\"";
// after
p.StartInfo.Arguments = $"-NonInteractive -ExecutionPolicy Bypass -Command \"{psScript}\"";
Defensive patterns

Strategy: fallback

Validate before calling

using var probe = Process.Start(new ProcessStartInfo("powershell.exe", "-NonInteractive -Command Get-Command Get-AppxPackage") { UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true });
string probeOut = probe.StandardOutput.ReadToEnd();
probe.WaitForExit();
bool appxAvailable = probe.ExitCode == 0 && probeOut.Contains("Get-AppxPackage");
if (!appxAvailable) { /* show UWP list as unavailable instead of erroring */ }

Try / catch

try { await LoadAppListAsync(); }
catch (Exception ex) when (ex.Message.StartsWith("PowerShell 错误"))
{ MessageBox.Show($"无法枚举 UWP 应用:{ex.Message}\n可能被策略限制或 AppX 服务被禁用。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); }

Prevention

When it happens

Trigger: Calling LoadAppListAsync (on Appx control load or refresh button) when powershell.exe returns non-zero: PowerShell blocked by execution policy/AppLocker, Get-AppxPackage cmdlet missing (very old Windows / stripped-down LTSB builds), AppX deployment service (AppXSvc) disabled, or profile/registry corruption making the cmdlet throw.

Common situations: Heavily debloated Windows images with AppX services removed; corporate AppLocker/WDAC policies blocking unsigned PowerShell; broken user profile where Get-AppxPackage throws permission errors; running on Windows Server without the AppX module.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


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

Appendix: source

Thrown at ZyperWin++/ZyperWin++/Appx.cs:81

                            p.StartInfo.RedirectStandardError = true;
                            p.StartInfo.CreateNoWindow = true;

                            p.Start();

                            string output = p.StandardOutput.ReadToEnd();
                            string error = p.StandardError.ReadToEnd();
                            p.WaitForExit();

                            if (p.ExitCode == 0)
                            {
                                packages = output.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                                                 .Select(s => s.Trim())
                                                 .Where(s => !string.IsNullOrEmpty(s))
                                                 .ToList();
                            }
                            else
                            {
                                throw new Exception("PowerShell 错误: " + error);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        packages.Clear();
                        packages.Add("加载失败: " + ex.Message);
                    }
                });

                checkedListBox1.Invoke((MethodInvoker)delegate
                {
                    checkedListBox1.Items.Clear();
                    if (packages.Count > 0 && !packages[0].StartsWith("加载失败"))
                    {
                        foreach (string pkg in packages)
                        {
                            checkedListBox1.Items.Add(pkg, false);

View on GitHub (pinned to d20e78bbd9)