检索UWP中默认打印机驱动程序的IP地址 [英] Retrieve IP Address of the Default Printer Driver in UWP

查看:98
本文介绍了检索UWP中默认打印机驱动程序的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要在UWP应用的控制面板中的默认打印机驱动程序中获取配置的打印机IP地址。

We have a requirement to get the printer IP Address configured in the default printer driver in Control Panel in our UWP app.

我能够检索到 <通过获取接口类GUID并将此上面的属性传递以进行检索,从而实现 strong> System.DeviceInterface.PrinterPortName 。

但是我无法获得类似的 System.Devices.IpAddress。
下面为PortName粘贴的代码。

But I couldn't get "System.Devices.IpAddress" similarly. Code pasted below for PortName.

我非常需要IP地址,因为端口名称是用户选择的,可以修改为删除IP地址的任何名称。

I badly need the IP address as the port name is user's choice and could be modified to any name removing the IP address.

请善用以上属性或通过UWP应用程序中的任何其他方式来共享工作代码以检索IP地址。

Kindly help sharing working code to retrieve the IP Address using above property or any other way in UWP app.

下面是端口名称的工作代码,请帮助获取相同端口的IP地址类似。

Below is Working Code for Port Name, Kindly help to fetch IP Address of the same port similarly.

        string aqsFilter = "System.Devices.InterfaceClassGuid:=\"{0ecef634-6ef0-472a-8085-5ad023ecbccd}\"";

        string[] propertiesToRetrieve = new string[] { "System.DeviceInterface.PrinterPortName"};

        DeviceInformationCollection deviceInfoCollection = await DeviceInformation.FindAllAsync(aqsFilter, propertiesToRetrieve);

        foreach (DeviceInformation deviceInfo in deviceInfoCollection)
        {
            if (deviceInfo.IsDefault == true)
            {
                string strPortName = (string)deviceInfo.Properties["System.DeviceInterface.PrinterPortName"];

                if (!string.IsNullOrEmpty(strPortName))
                {
                    strPortName = await ParsePortName(strPortName);
                    if (!string.IsNullOrEmpty(strPortName))
                    {
                        _strIPAddress = strPortName;
                    }
                }
                break;
            }
        }


推荐答案

这不被认可,因为IP地址可以更改,因此不可靠。

话虽如此,如果您的打印机是使用wsd安装的,在技​​术上受支持
例如,
DEVPKEY_PNPX_IpAddress DEVPROP_TYPE_STRING_LIST 32 10.137.192.202
但是如果不进行大量各种方案检查,就无法可靠地使用此功能,因为IP地址可能会更改。

That being said, if your printer is installed using wsd, it is technically supported E.g., DEVPKEY_PNPX_IpAddress DEVPROP_TYPE_STRING_LIST 32 "10.137.192.202" But there is no way to reliably use this without a lot of various scenario checks since the IP address may change.

此外,在此示例中,您没有找到DAF提供程序,而是在寻找设备。您正在使用0ecef634-6ef0-472a-8085-5ad023ecbccd,它是打印机类的guid。看起来IP地址也不在PnP Explorer属性包中传播,因此IP地址不可访问。

Furthermore, looking at this example, you are not hitting the DAF providers but looking for devices. You are using 0ecef634-6ef0-472a-8085-5ad023ecbccd which is the printer class guid. It also does not look like IP address is propagated in the PnP Explorer property bag so the IP address is not accessible.

这篇关于检索UWP中默认打印机驱动程序的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆