连接包含空格的网络打印机
Connect network printer that contains spaces
我使用以下映射网络打印机
using (Process p = new Process())
{
Console.WriteLine("Attempting to add: {0}", newPrinter);
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = string.Format("/c start {0}", newPrinter);
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.WaitForExit();
if (Convert.ToInt16(row["IsDefault"]) != 0)
{
Console.WriteLine("Setting Default");
NativeMethods.SetDefaultPrinter(newPrinter);
}
当打印机名称包含 space 时,它会在 space 之前将其截断。
我怎样才能让它识别带有 space 的打印机的 UNC 并连接它?
怎么样
p.StartInfo.Arguments = string.Format("/c start \"{0}\"", newPrinter);
这样行吗?
编辑:
或改用 WMI:
我使用以下映射网络打印机
using (Process p = new Process())
{
Console.WriteLine("Attempting to add: {0}", newPrinter);
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = string.Format("/c start {0}", newPrinter);
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.WaitForExit();
if (Convert.ToInt16(row["IsDefault"]) != 0)
{
Console.WriteLine("Setting Default");
NativeMethods.SetDefaultPrinter(newPrinter);
}
当打印机名称包含 space 时,它会在 space 之前将其截断。 我怎样才能让它识别带有 space 的打印机的 UNC 并连接它?
怎么样
p.StartInfo.Arguments = string.Format("/c start \"{0}\"", newPrinter);
这样行吗?
编辑:
或改用 WMI: