Windows平台使用VDS获取主机端IQN
来源:互联网 发布:淘宝怎么关联小号 编辑:程序博客网 时间:2024/06/07 03:49
先看一下定义在vds.h中关于iSCSI的VDS Interface:IVdsServiceIscsi
EXTERN_C const IID IID_IVdsServiceIscsi; MIDL_INTERFACE("14fbe036-3ed7-4e10-90e9-a5ff991aff01") IVdsServiceIscsi : public IUnknown { public: virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE GetInitiatorName( /* [string][out] */ __RPC__deref_out_opt_string LPWSTR *ppwszIscsiName) = 0; virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE QueryInitiatorAdapters( /* [out] */ __RPC__deref_out_opt IEnumVdsObject **ppEnum) = 0; virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE SetIpsecGroupPresharedKey( /* [unique][in] */ __RPC__in_opt VDS_ISCSI_IPSEC_KEY *pIpsecKey) = 0; virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE SetAllIpsecTunnelAddresses( /* [in] */ __RPC__in VDS_IPADDRESS *pTunnelAddress, /* [in] */ __RPC__in VDS_IPADDRESS *pDestinationAddress) = 0; virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE SetAllIpsecSecurity( /* [in] */ VDS_OBJECT_ID targetPortalId, /* [in] */ ULONGLONG ullSecurityFlags, /* [unique][in] */ __RPC__in_opt VDS_ISCSI_IPSEC_KEY *pIpsecKey) = 0; virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE SetInitiatorSharedSecret( /* [unique][in] */ __RPC__in_opt VDS_ISCSI_SHARED_SECRET *pInitiatorSharedSecret, /* [in] */ VDS_OBJECT_ID targetId) = 0; virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE RememberTargetSharedSecret( /* [in] */ VDS_OBJECT_ID targetId, /* [unique][in] */ __RPC__in_opt VDS_ISCSI_SHARED_SECRET *pTargetSharedSecret) = 0; };
调用GetInitiatorName即可获取到IQN
void GetiSCSIIQN(void){ HRESULT hResult = CoInitialize(NULL); if (!SUCCEEDED(hResult)) { cout << "VDS Service failed hr=%x" << hResult << endl; return; } // %SystemRoot%\System32\vdsldr.exe IVdsServiceLoader *pLoader = NULL; hResult = CoCreateInstance(CLSID_VdsLoader, NULL, CLSCTX_LOCAL_SERVER, IID_IVdsServiceLoader, (void**)&pLoader); if (!SUCCEEDED(hResult)) { cout << "CoCreateInstance failed" << endl; return; } IVdsService* pService = NULL; hResult = pLoader->LoadService(NULL, &pService); if (!SUCCEEDED(hResult)) { cout << GetLastError() << endl; cout << "LoadService failed: " << hex << hResult << endl; return; } // release pLoader. if (pLoader) { pLoader->Release(); pLoader = NULL; } hResult = pService->WaitForServiceReady(); if (!SUCCEEDED(hResult)) { cout << "WaitForServiceReady failed, Error Code: " << GetLastError() << endl; return; } // Query IVdsServiceIscsi IVdsServiceIscsi *iSCSIServer = NULL; hResult = pService->QueryInterface(IID_IVdsServiceIscsi, (void**)&iSCSIServer); if (!SUCCEEDED(hResult)) { cout << "QueryInterface IVdsServiceIscsi failed, Error Code: " << GetLastError() << endl; return; } // Get IQN, Memory Manager must use CoTaskMemAlloc/CoTaskMemFree. LPWSTR pInitiatorName = (WCHAR*)CoTaskMemAlloc(sizeof(WCHAR) * MAX_PATH); hResult = iSCSIServer->GetInitiatorName(&pInitiatorName); if (!SUCCEEDED(hResult)) { cout << "GetInitiatorName failed, Error Code: " << GetLastError() << endl; if (NULL != pInitiatorName) { CoTaskMemFree(pInitiatorName); pInitiatorName = NULL; } return; } wcout << "Local Machine IQN: " << pIQN << endl; if (NULL != pInitiatorName) { CoTaskMemFree(pInitiatorName); pInitiatorName = NULL; } return;}
运行后,居然抛错:
GetInitiatorName failed, Error Code: 14007
查看了一下System Error Code:
System error 14007 has occurred. The requested lookup key was not found in any active activation context.
信息有点晦涩,但是想起来似乎MSiSCSI服务没起来,
C:\Users\sha>sc start msiscsi
SERVICE_NAME: msiscsi
TYPE : 20 WIN32_SHARE_PROCESS
STATE : 2 START_PENDING
(NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x7d0
PID : 464
FLAGS :
再次运行:
Local Machine IQN: iqn.1991-05.com.microsoft:bendsha
- Windows平台使用VDS获取主机端IQN
- 多主机同时使用同一个iscsi iqn,且写数据不冲突
- 使用windows API获取本地主机的MAC地址
- 在windows平台上使用Qt和libmodbus库实现modbus主机功能
- 使用cacti监控windows主机
- 使用Zabbix监控Windows主机
- 在windows下获取主机ip地址
- C#: WMI 获取远程 Windows 主机信息
- 使用Spring的ResourceLoader获取文件夹在主机的实际位置(windows和linux通用)
- Windows平台使用Github
- windows平台select使用
- windows平台Mosquitto使用
- 使用gethostbyname获取主机的各种信息
- linux shell使用gmond获取主机性能参数
- 使用ACE获取主机的IP地址
- Openstack-Ceilometer-获取主机内存 的使用
- windows 主机查看端口使用情况
- Java获取主机IP地址,自动区分Windows和Linux
- 修复windows installer安装错误
- mogodb 添加用户不成功
- BMP格式知识之一:BMP位图文件的存储格式
- lua学习笔记(2)——内核入口
- Sidekiq最佳实践
- Windows平台使用VDS获取主机端IQN
- 数字变为字符串
- form表单的ajax提交【组装json】
- 前端开发框架对比
- 使用Java添加系统右键菜单---修改篇
- Android4.4——InputManagerService之InputReader线程
- Android调用系统相机和自定义相机实例
- c语言从文件中读入格式化数据并存入sqlite3
- IBM 笔记本错误对应码