【发布时间】:2021-12-18 18:54:16
【问题描述】:
我想用 c# 制作打印机安装程序 gui,但我给出了错误。 我的错误如下。enter image description here
System.Management.Automation.CommandNotFoundException: '术语'添加' 未被识别为 cmdlet、函数、脚本文件的名称,或 可运行的程序。检查名称的拼写,或者路径是否 包含,验证路径是否正确,然后重试。'
我的代码如下,我哪里做错了?我正在等待你的帮助。我苦苦挣扎了3天,我查看了所有资源,但找不到解决方案。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Management.Automation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace son1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void ekle_Click(object sender, EventArgs e)
{
using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create())
{
powershell.AddCommand("Add");
powershell.AddArgument("-");
powershell.AddArgument("PrinterPort");
powershell.AddArgument("-");
powershell.AddArgument("name");
powershell.AddArgument(printer_ip);
powershell.AddArgument("-");
powershell.AddArgument("PrinterHostAddress");
powershell.AddArgument(printer_ip);
powershell.Invoke();
}
using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create())
{
powershell.AddCommand("Add");
powershell.AddArgument("-");
powershell.AddArgument("Printer");
powershell.AddArgument("-");
powershell.AddArgument("Name");
powershell.AddArgument(printer_name);
powershell.AddArgument("-");
powershell.AddArgument("PortName");
powershell.AddArgument(printer_ip);
powershell.AddArgument("-");
powershell.AddArgument("DriverName");
powershell.AddArgument("Canon Generic Plus PCL6");
powershell.Invoke();
}
System.Windows.MessageBox.Show("Success!");
}
}
}
【问题讨论】:
-
如果您可以将问题中的错误以文本的形式包含在内,这将使这里的人们比一个非常大的图像的链接更容易看到,而且它将帮助人们在未来寻找解决方案同样的错误。
-
谢谢,已编辑。
标签: c# powershell