winforms 检查网络使用lpt1中连接的打印机

rks48beu  于 2023-03-19  发布在  其他
关注(0)|答案(1)|浏览(116)

我有一个问题,在这个程序中我Map了一个标签网络打印机,所以我想知道我连接到了哪台打印机,这是我的函数。有什么函数可以让我知道我连接的打印机在哪里吗?
例如“您已连接到打印机“DESKTOP01”

public void impressora(string computador)
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = "cmd.exe";
    startInfo.Arguments = $@"/c net use lpt1: /delete & net use lpt1: \\{computador}\zpl";
    process.StartInfo = startInfo;
    process. Start();
}
4xy9mtcn

4xy9mtcn1#

所以我找到了如何得到回应...

public void checkimpressora()
    {
        System.Diagnostics.Process process = new System.Diagnostics.Process();
        process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        process.StartInfo.FileName = "cmd.exe";
        process.StartInfo.Arguments = $@"/c net use lpt1:";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.CreateNoWindow = true;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardInput = true;
        process.Start();
        string q = "";
        q += process.StandardOutput.ReadToEnd();
        string m = q.Replace("Local name        LPT1", " ").Replace("Resource type     Print", " ").Replace("Status            OK", " ").Replace("# Opens           0", "").Replace("# Connections     1", " ").Replace("The command completed successfully.", " ").Replace(@"Remote name       \\", " ").Replace(@"\zpl", " ").Replace(" ", "").Replace("\r\n", "");
        if (m != "")
        {
            if (m == "BRMAOPR094")
            {
                resetallbuttons();
                changecolor(pcm);
            }
        } 
    }

相关问题