如何找出WSD打印机的IP地址?我想使用 WSD API,但无法使用 IWSDDiscoveredDevice
how to find out IP address of WSD printer ? i want to use WSD APIs, but unable to get using IWSDDiscoveredDevice
我尝试过使用WSDDeviceProxy,特别是在GetMetadata中,我正在获取除IP地址之外的所有打印机信息。 在一个站点中,我读到IP可以通过IWSDDiscoveredDevice获得,但是如何创建IWSDDiscoverDevice?
前段时间我遇到了类似的问题:查找已安装的 WSD 打印队列的传输地址。好的起点是阅读规范:http://docs.oasis-open.org/ws-dd/discovery/1.1/wsdd-discovery-1.1-spec.pdf。
如果处理已安装的 WSD 打印机队列,则具有打印机 UUID,并且可能只需发送 Resolve 请求并侦听 ResolveMatch 响应。最简单的实用方法是:
- 通过枚举打印机获取打印机队列端口名称(我使用了级别 5)
- 通过枚举端口获取端口监视器
- 从注册表路径获取"打印机 UUID"
计算机\HKEY_LOCAL_MACHINE\系统\当前控制集\控制\打印\监视器\WSD端口\端口
-
使用 utf-8 编码数据将 UDP 数据包发送到地址 239.255.255.250 端口 3702
<soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" xmlns:wsa=""http://schemas.xmlsoap.org/ws/2004/08/addressing"" xmlns:wsd=""http://schemas.xmlsoap.org/ws/2005/04/discovery""> <soap:Header> <wsa:To>urn:schemas-xmlsoap-org:ws:2005:04:discovery</wsa:To> <wsa:Action>http://schemas.xmlsoap.org/ws/2005/04/discovery/Resolve</wsa:Action> <wsa:MessageID>{0}</wsa:MessageID> </soap:Header> <soap:Body> <wsd:Resolve> <wsa:EndpointReference> <wsa:Address>{1}</wsa:Address> </wsa:EndpointReference> </wsd:Resolve> </soap:Body> </soap:Envelope>"
其中 messageId urn:uuid:<GENERATED_GUID>
,地址urn:uuid:<PRINTER_UUID>
-
接收 UDP 单播响应
-
传输地址存储在
<wsd:XAddrs>
示例解析匹配:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsd="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsdp="http://schemas.xmlsoap.org/ws/2006/02/devprof" xmlns:wsvc0="http://schemas.microsoft.com/windows/2006/08/wdp/scan" xmlns:wsvc1="http://schemas.microsoft.com/windows/2006/08/wdp/print">
<soap:Header>
<wsa:Action>http://schemas.xmlsoap.org/ws/2005/04/discovery/ResolveMatches</wsa:Action>
<wsa:MessageID>urn:uuid:d8a491ad-0d87-4429-b900-84f102a91097</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:8fc371bb-edfb-49a4-b631-7e5264e25c20</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsd:AppSequence InstanceId="1529651446" MessageNumber="1790"/>
</soap:Header>
<soap:Body>
<wsd:ResolveMatches>
<wsd:ResolveMatch>
<wsa:EndpointReference>
<wsa:Address>urn:uuid:edec3c87-cfbc-4b02-bcb8-077be723bd32</wsa:Address>
</wsa:EndpointReference>
<wsd:XAddrs>http://192.168.1.101:65001 http://[fe80::221:b7ff:fe19:8a4a]:65001</wsd:XAddrs>
<wsd:MetadataVersion>168</wsd:MetadataVersion>
</wsd:ResolveMatch>
</wsd:ResolveMatches>
</soap:Body>
</soap:Envelope>
如果您不处理已安装的打印队列,则必须执行 Probe 请求,侦听 ProbeMatch,然后才进行 Resolve/ResolveMatch。
我最终得到了 200 行完全托管的最小解决方案。如果您正在寻找 WSDAAPI,请查看以下示例(只是一个想法,肯定还没有准备好生产):
WSDiscoveryProviderNotifier.cpp:
#include <Wsdapi.h>
#include <Wsddisco.h>
#include "guid_helper.h"
import std.core;
constexpr const IID IID_WSDiscoveryProviderNotifier = guid_parse::make_guid("{EFECF0A1-399E-40B8-A13C-ACE28DB40212}");
class WSDiscoveryProviderNotifier : public IWSDiscoveryProviderNotify {
private:
LONG referenceCount = 0;
public:
/* IUnknown */
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID *ppvObj) override {
// Always set out parameter to NULL, validating it first.
if (!ppvObj)
return E_INVALIDARG;
*ppvObj = nullptr;
if (riid == IID_IUnknown || riid == IID_WSDiscoveryProviderNotifier) {
// Increment the reference count and return the pointer.
*ppvObj = (LPVOID) this;
AddRef();
return NOERROR;
}
return E_NOINTERFACE;
}
ULONG STDMETHODCALLTYPE AddRef() override {
InterlockedIncrement(&referenceCount);
return referenceCount;
};
ULONG STDMETHODCALLTYPE Release() override {
ULONG ulRefCount = InterlockedDecrement(&referenceCount);
if (0 == ulRefCount)
{
delete this;
}
return ulRefCount;
};
/* IWSDiscoveryProviderNotify */
HRESULT STDMETHODCALLTYPE SearchFailed(
/* [in] */ HRESULT hr,
/* [annotation][optional][in] */
_In_opt_ LPCWSTR pszTag) override {
std::wcout << "Search failed" << std::endl;
return S_OK;
}
HRESULT STDMETHODCALLTYPE SearchComplete(
/* [annotation][optional][in] */
_In_opt_ LPCWSTR pszTag) override {
std::wcout << "Search completed" << std::endl;;
return S_OK;
}
HRESULT STDMETHODCALLTYPE Add (/* [in] */ IWSDiscoveredService *pService) override {
WSD_URI_LIST *uriList;
pService->GetXAddrs(&uriList);
WSD_URI_LIST *currentElement = uriList;
do {
std::wcout << currentElement->Element << std::endl;
currentElement = currentElement->Next;
}
while (currentElement != nullptr);
return S_OK;
}
HRESULT STDMETHODCALLTYPE Remove(/* [in] */ IWSDiscoveredService *pService) override {
return S_OK;
};
};
主.cpp:
#include <Wsdxml.h>
#include "WSDiscoveryProviderNotifier.cpp"
void ResolveWSDDeviceById(LPCWSTR deviceId) {
HRESULT hr = S_OK;
IWSDXMLContext *context = nullptr;
IWSDiscoveryProvider *discoveryProvider = nullptr;
IWSDiscoveryProviderNotify *providerNotifier = new WSDiscoveryProviderNotifier();
hr = WSDCreateDiscoveryProvider(context, &discoveryProvider);
if (S_OK == hr) {
std::wcout << "WSDCreateDiscoveryProvider reported success" << std::endl;
discoveryProvider->Attach(providerNotifier);
discoveryProvider->SearchById(deviceId, nullptr);
} else {
throw std::exception("Failed to create IWSDiscoveryProvider");
}
}
int main() {
std::cout << "Hello, World!" << std::endl;
ResolveWSDDeviceById(L"urn:uuid:edec3c87-cfbc-4b02-bcb8-077be723bd32");
std::string _;
std::getline (std::cin,_);
return 0;
}
希望这对某人有所帮助。
- 用于访问容器<T>数据成员的正确 API
- 如何使用Luacneneneba API正确读取字符串和表参数
- C++MySQL C api用户输入行
- 如何使用 AWS Transcribe C++ API 中的'StartTranscriptionJobRequest'?
- 将std::string传递给WriteConsole API
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 在gtest.中使用fff.h模拟系统API
- 有没有任务栏API可以立即应用注册表更改
- C++win32 API创建多个类似视口的窗口
- 使用libcurl提交批量url的正确BING Api POST url是什么
- 如何将真正的字符串从python c-api转换为python脚本
- 使用Qt框架在c ++类中创建API调用
- Libreoffice API (UNO):需要更改用户的 xTextField 文本
- 使用 WIN32 API (C/C++) 对特定树视图项进行着色
- 使用 Python Extension API 包装复杂C++类
- 如何使用 samtools C API 构建一个简单的主.cpp文件
- 第三方 API 中的编译错误 - Visual Studio
- Tensorflow c++ api undefined reference to 'tflite::D efaultErrorReporter()'
- clang 的 libFuzzer 可以在同一二进制文件中测试超过 1 个 API 吗?
- 如何找出WSD打印机的IP地址?我想使用 WSD API,但无法使用 IWSDDiscoveredDevice