c# - WPF检查系统上是否安装了python

标签 c# python wpf cmd

我的 wpf 应用程序调用 python 脚本来生成稍后显示在 UI 中的输出。如果用户系统上没有安装 python,为了避免应用程序崩溃,我需要执行检查。目前我已经实现了使用以下内容

ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"cmd.exe"; // Specify exe name.
start.Arguments = "python --version";
start.UseShellExecute = false;
start.RedirectStandardError = true;

using (Process process = Process.Start(start))
        {
            using (StreamReader reader = process.StandardError)
            {
                string result = reader.ReadToEnd();
                MessageBox.Show(result);
            }
        }

这完成了工作,但会导致 cmd 黑色窗口瞬间出现,这是非常不希望的。是否有实现此目的的解决方法或避免出现窗口的修复程序?

最佳答案

或者,您可以检查注册表中键 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe 的默认值

这可以说比仅仅尝试运行 python.exe 更可靠,因为 Python 安装程序并不总是更新 PATH 变量。

关于c# - WPF检查系统上是否安装了python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22694028/

相关文章:

c# - 如何确定给定方法可以抛出哪些异常?

javascript - 如何在 MVC 中的模型 View 中重置字段编辑器

python - 如何在 selenium 驱动程序 linux python 上设置 firefox 配置文件

python - wxPython StyleSetSpec 和 SetLexer 不工作?

python Pandas DataFrame 复制(deep=False)vs 复制(deep=True)vs '='

c# - 在RowFilter中,如何在C#中选择所有表列?

c# - 返回未经授权的 ViewResult

c# - PRISM (Unity) 中的 ViewModelLocator 在模块中不起作用

c# - 如何从 PropertyChanged 事件中正确重置与 ComboBox 关联的值?

c# - 单击 "Link"后 WPF Modern UI 弹出现代对话框