SAFEARRAY - pobieranie adresu ip karty sieciowej

SAFEARRAY - pobieranie adresu ip karty sieciowej
M1
  • Rejestracja:prawie 11 lat
  • Ostatnio:ponad 8 lat
  • Postów:165
0

Witam,

Mam problem z pobraniem adresów ip z bazy "wmi". Z tego co wyczytałem z dokumentacji w MSDN należy do pobraniu użyć SAFEARRAY, tylko że w internecie nie ma przykładów jak użyć tej funkcji. Typ danych zwracanych z bazy to VT_BSTR + VT_ARRAY.

Kod pobierający adresy ip z bazy powinien być w tym miejscu :

Kopiuj
if ((vtProp.vt & VT_ARRAY))
                        wcout << "IPAddress : " << "Array types not supported (yet)" << endl;

Kawałek kodu :

Kopiuj
...

if (!localconn)
    {

        hres = CoSetProxyBlanket(
            pEnumerator,                    // Indicates the proxy to set
            RPC_C_AUTHN_DEFAULT,            // RPC_C_AUTHN_xxx
            RPC_C_AUTHZ_DEFAULT,            // RPC_C_AUTHZ_xxx
            COLE_DEFAULT_PRINCIPAL,         // Server principal name
            RPC_C_AUTHN_LEVEL_PKT_PRIVACY,  // RPC_C_AUTHN_LEVEL_xxx
            RPC_C_IMP_LEVEL_IMPERSONATE,    // RPC_C_IMP_LEVEL_xxx
            userAcct,                       // client identity
            EOAC_NONE                       // proxy capabilities
            );

        if (FAILED(hres))
        {
            cout << "Could not set proxy blanket on enumerator. Error code = 0x" << hex << hres << endl;
            cout << _com_error(hres).ErrorMessage() << endl;
            pEnumerator->Release();
            pSvc->Release();
            pLoc->Release();
            CoUninitialize();
            cout << "press enter to exit" << endl;
            cin.get();
            return 1;               // Program has failed.
        }
    }

    // Get the data from the WQL sentence
    IWbemClassObject *pclsObj = NULL;
    ULONG uReturn = 0;

    while (pEnumerator)
    {
        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);

        if(0 == uReturn || FAILED(hr))
          break;


        VARIANT vtProp;

                hr = pclsObj->Get(L"IPAddress", 0, &vtProp, 0, 0);// String
                if (!FAILED(hr))
                {
                  if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
                    wcout << "IPAddress : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
                  else{
                    if ((vtProp.vt & VT_ARRAY))
                        wcout << "IPAddress : " << "Array types not supported (yet)" << endl;
                    else
                        wcout << "IPAddress : " << vtProp.bstrVal << endl;
                  }
                }
                VariantClear(&vtProp);


        pclsObj->Release();
        pclsObj=NULL;
    }


    // Cleanup

    pSvc->Release();
    pLoc->Release();
    pEnumerator->Release();
    if (pclsObj!=NULL)
     pclsObj->Release();

    CoUninitialize();
    return 0;   // Program successfully completed.

...
Azarien
  • Rejestracja:ponad 21 lat
  • Ostatnio:2 minuty
0

czym jest pEnumerator? daj taki kod, który da się skompilować i testować...

M1
  • Rejestracja:prawie 11 lat
  • Ostatnio:ponad 8 lat
  • Postów:165
0

@Azarien łap cały kod

Kopiuj
//-----------------------------------------------------------------------------------------------------
//     This code was generated by the Wmi Delphi Code Creator (WDCC) Version 1.8.5.0
//     http://code.google.com/p/wmi-delphi-code-creator/
//     Blog http://theroadtodelphi.wordpress.com/wmi-delphi-code-creator/
//     Author Rodrigo Ruz V. (RRUZ) Copyright (C) 2011-2014
//-----------------------------------------------------------------------------------------------------
//
//     LIABILITY DISCLAIMER
//     THIS GENERATED CODE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.
//     YOU USE IT AT YOUR OWN RISK. THE AUTHOR NOT WILL BE LIABLE FOR DATA LOSS,
//     DAMAGES AND LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS CODE.
//
//----------------------------------------------------------------------------------------------------

#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h>
# pragma comment(lib, "wbemuuid.lib")

//CREDENTIAL structure
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa374788%28v=vs.85%29.aspx
#define CRED_MAX_USERNAME_LENGTH            513
#define CRED_MAX_CREDENTIAL_BLOB_SIZE       512
#define CREDUI_MAX_USERNAME_LENGTH CRED_MAX_USERNAME_LENGTH
#define CREDUI_MAX_PASSWORD_LENGTH (CRED_MAX_CREDENTIAL_BLOB_SIZE / 2)

// The Win32_NetworkAdapterConfiguration class represents the attributes and
// behaviors of a network adapter. This class has been extended to include extra
// properties and methods that support the management of the TCP/IPprotocols (and
// are independent of the network adapter).

#pragma argsused
int main(int argc, char* argv[])
{
    wchar_t pszName[CREDUI_MAX_USERNAME_LENGTH+1] = L"user";
    wchar_t pszPwd[CREDUI_MAX_PASSWORD_LENGTH+1]  = L"password";
    BSTR strNetworkResource;
    //To use a WMI remote connection set localconn to false and configure the values of the pszName, pszPwd and the name of the remote machine in strNetworkResource
    bool localconn = true;
    strNetworkResource = localconn ?  L"\\\\.\\root\\CIMV2" : L"\\\\remote--machine\\root\\CIMV2";

    COAUTHIDENTITY *userAcct =  NULL ;
    COAUTHIDENTITY authIdent;

    // Initialize COM. ------------------------------------------

    HRESULT hres;
    hres =  CoInitializeEx(0, COINIT_MULTITHREADED);
    if (FAILED(hres))
    {
        cout << "Failed to initialize COM library. Error code = 0x"	<< hex << hres << endl;
        cout << _com_error(hres).ErrorMessage() << endl;
        cout << "press enter to exit" << endl;
        cin.get();
        return 1;                  // Program has failed.
    }

    // Set general COM security levels --------------------------

    if (localconn)
        hres =  CoInitializeSecurity(
            NULL,
            -1,                          // COM authentication
            NULL,                        // Authentication services
            NULL,                        // Reserved
            RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication
            RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
            NULL,                        // Authentication info
            EOAC_NONE,                   // Additional capabilities
            NULL                         // Reserved
            );
    else
        hres =  CoInitializeSecurity(
            NULL,
            -1,                          // COM authentication
            NULL,                        // Authentication services
            NULL,                        // Reserved
            RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication
            RPC_C_IMP_LEVEL_IDENTIFY,    // Default Impersonation
            NULL,                        // Authentication info
            EOAC_NONE,                   // Additional capabilities
            NULL                         // Reserved
            );

    if (FAILED(hres))
    {
        cout << "Failed to initialize security. Error code = 0x" << hex << hres << endl;
        cout << _com_error(hres).ErrorMessage() << endl;
        CoUninitialize();
        cout << "press enter to exit" << endl;
        cin.get();
        return 1;                    // Program has failed.
    }

    // Obtain the initial locator to WMI -------------------------

    IWbemLocator *pLoc = NULL;
    hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);

    if (FAILED(hres))
    {
        cout << "Failed to create IWbemLocator object."	<< " Err code = 0x" << hex << hres << endl;
        cout << _com_error(hres).ErrorMessage() << endl;
        CoUninitialize();
        cout << "press enter to exit" << endl;
        cin.get();
        return 1;                 // Program has failed.
    }

    // Connect to WMI through the IWbemLocator::ConnectServer method

    IWbemServices *pSvc = NULL;

    if (localconn)
        hres = pLoc->ConnectServer(
             _bstr_t(strNetworkResource),      // Object path of WMI namespace
             NULL,                    // User name. NULL = current user
             NULL,                    // User password. NULL = current
             0,                       // Locale. NULL indicates current
             NULL,                    // Security flags.
             0,                       // Authority (e.g. Kerberos)
             0,                       // Context object
             &pSvc                    // pointer to IWbemServices proxy
             );
    else
        hres = pLoc->ConnectServer(
            _bstr_t(strNetworkResource),  // Object path of WMI namespace
            _bstr_t(pszName),             // User name
            _bstr_t(pszPwd),              // User password
            NULL,                // Locale
            NULL,                // Security flags
            NULL,				 // Authority
            NULL,                // Context object
            &pSvc                // IWbemServices proxy
            );

    if (FAILED(hres))
    {
        cout << "Could not connect. Error code = 0x" << hex << hres << endl;
        cout << _com_error(hres).ErrorMessage() << endl;
        pLoc->Release();
        CoUninitialize();
        cout << "press enter to exit" << endl;
        cin.get();
        return 1;                // Program has failed.
    }

    cout << "Connected to root\\CIMV2 WMI namespace" << endl;

    // Set security levels on the proxy -------------------------
    if (localconn)
        hres = CoSetProxyBlanket(
           pSvc,                        // Indicates the proxy to set
           RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
           RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
           NULL,                        // Server principal name
           RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx
           RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
           NULL,                        // client identity
           EOAC_NONE                    // proxy capabilities
        );
    else
    {
        // Create COAUTHIDENTITY that can be used for setting security on proxy
        memset(&authIdent, 0, sizeof(COAUTHIDENTITY));
        authIdent.PasswordLength = wcslen (pszPwd);
        authIdent.Password = (USHORT*)pszPwd;
        authIdent.User = (USHORT*)pszName;
        authIdent.UserLength = wcslen(pszName);
        authIdent.Domain = 0;
        authIdent.DomainLength = 0;
        authIdent.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
        userAcct = &authIdent;

        hres = CoSetProxyBlanket(
           pSvc,                           // Indicates the proxy to set
           RPC_C_AUTHN_DEFAULT,            // RPC_C_AUTHN_xxx
           RPC_C_AUTHZ_DEFAULT,            // RPC_C_AUTHZ_xxx
           COLE_DEFAULT_PRINCIPAL,         // Server principal name
           RPC_C_AUTHN_LEVEL_PKT_PRIVACY,  // RPC_C_AUTHN_LEVEL_xxx
           RPC_C_IMP_LEVEL_IMPERSONATE,    // RPC_C_IMP_LEVEL_xxx
           userAcct,                       // client identity
           EOAC_NONE                       // proxy capabilities
        );
    }

    if (FAILED(hres))
    {
        cout << "Could not set proxy blanket. Error code = 0x" << hex << hres << endl;
        cout << _com_error(hres).ErrorMessage() << endl;
        pSvc->Release();
        pLoc->Release();
        CoUninitialize();
        cout << "press enter to exit" << endl;
        cin.get();
        return 1;               // Program has failed.
    }

    // Use the IWbemServices pointer to make requests of WMI ----

    IEnumWbemClassObject* pEnumerator = NULL;
    hres = pSvc->ExecQuery(	L"WQL",	L"SELECT * FROM Win32_NetworkAdapterConfiguration",
    WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);

    if (FAILED(hres))
    {
        cout << "ExecQuery failed" << " Error code = 0x"	<< hex << hres << endl;
        cout << _com_error(hres).ErrorMessage() << endl;
        pSvc->Release();
        pLoc->Release();
        CoUninitialize();
        cout << "press enter to exit" << endl;
        cin.get();
        return 1;               // Program has failed.
    }

    // Secure the enumerator proxy
    if (!localconn)
    {

        hres = CoSetProxyBlanket(
            pEnumerator,                    // Indicates the proxy to set
            RPC_C_AUTHN_DEFAULT,            // RPC_C_AUTHN_xxx
            RPC_C_AUTHZ_DEFAULT,            // RPC_C_AUTHZ_xxx
            COLE_DEFAULT_PRINCIPAL,         // Server principal name
            RPC_C_AUTHN_LEVEL_PKT_PRIVACY,  // RPC_C_AUTHN_LEVEL_xxx
            RPC_C_IMP_LEVEL_IMPERSONATE,    // RPC_C_IMP_LEVEL_xxx
            userAcct,                       // client identity
            EOAC_NONE                       // proxy capabilities
            );

        if (FAILED(hres))
        {
            cout << "Could not set proxy blanket on enumerator. Error code = 0x" << hex << hres << endl;
            cout << _com_error(hres).ErrorMessage() << endl;
            pEnumerator->Release();
            pSvc->Release();
            pLoc->Release();
            CoUninitialize();
            cout << "press enter to exit" << endl;
            cin.get();
            return 1;               // Program has failed.
        }
    }

    // Get the data from the WQL sentence
    IWbemClassObject *pclsObj = NULL;
    ULONG uReturn = 0;

    while (pEnumerator)
    {
        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);

        if(0 == uReturn || FAILED(hr))
          break;


        VARIANT vtProp;

                hr = pclsObj->Get(L"IPAddress", 0, &vtProp, 0, 0);// String
                if (!FAILED(hr))
                {
                  if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
                    wcout << "IPAddress : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
                  else{
                    if ((vtProp.vt & VT_ARRAY))
                        wcout << "IPAddress : " << "Array types not supported (yet)" << endl;
                    else
                        wcout << "IPAddress : " << vtProp.bstrVal << endl;
                  }
                }
                VariantClear(&vtProp);


        pclsObj->Release();
        pclsObj=NULL;
    }


    // Cleanup

    pSvc->Release();
    pLoc->Release();
    pEnumerator->Release();
    if (pclsObj!=NULL)
     pclsObj->Release();

    CoUninitialize();
    return 0;   // Program successfully completed.
}
 

PS. Wygenerowane za pomocą programu, tylko dlatego że szukałem przyczyny dlaczego to nie działa. Mam swój kod napisany też.

edytowany 1x, ostatnio: maniek1310
spartanPAGE
za takie generatory kodu powinno się ucinać członki.
n0name_l
... optymistycznie zakladajac jego obecnosc.
M1
  • Rejestracja:prawie 11 lat
  • Ostatnio:ponad 8 lat
  • Postów:165
1

Problem rozwiązany :)

Żeby nie było, że nie chcę pomagać innym to wrzucam jak udało mi się to zrobić.

Kopiuj
SAFEARRAY *psa = vtProp.parray;

if(psa)
{
    void **p = (void **)psa->pvData;
    wchar_t *wstr = (wchar_t *)*p;
    wcout << wstr << endl;
}
edytowany 1x, ostatnio: maniek1310
M1
  • Rejestracja:prawie 11 lat
  • Ostatnio:ponad 8 lat
  • Postów:165
0

Powyższy kod działa, ale jest kolejny problem :) A mianowicie zamiast pobrania "[8.8.8.8|194.204.152.34]" pobiera tylko "8.8.8.8"

Ps. Już działa. Ostateczny kod wygląda tak :

Kopiuj
SAFEARRAY *psa = vtProp.parray;

                            if(psa)
                            {
                                LONG uBound = -1, lBound = 0;
                                SafeArrayGetUBound(psa,1,&uBound);
                                SafeArrayGetLBound(psa,1,&lBound);
                                int nCount = uBound - lBound +1;
                                for(int i = 0; i < nCount; ++i)
                                {
                                    wcout << ((BSTR*)(psa->pvData))[i] << endl;
                                }
                            }
edytowany 2x, ostatnio: maniek1310
Azarien
  • Rejestracja:ponad 21 lat
  • Ostatnio:2 minuty
0
Kopiuj
#define _WIN32_DCOM
#include <iostream>
#include <clocale>
using namespace std;

#define _WIN32_WINNT 0x600
#include <comdef.h>
#include <Wbemidl.h>

# pragma comment(lib, "wbemuuid.lib")

#ifdef NDEBUG
#  pragma comment(lib,"comsuppw.lib")
#else
#  pragma comment(lib,"comsuppwd.lib")
#endif

//CREDENTIAL structure
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa374788%28v=vs.85%29.aspx
#define CRED_MAX_USERNAME_LENGTH            513
#define CRED_MAX_CREDENTIAL_BLOB_SIZE       512
#define CREDUI_MAX_USERNAME_LENGTH CRED_MAX_USERNAME_LENGTH
#define CREDUI_MAX_PASSWORD_LENGTH (CRED_MAX_CREDENTIAL_BLOB_SIZE / 2)

_COM_SMARTPTR_TYPEDEF(IWbemLocator, __uuidof(IWbemLocator));
_COM_SMARTPTR_TYPEDEF(IWbemServices, __uuidof(IWbemServices));
_COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, __uuidof(IEnumWbemClassObject));
_COM_SMARTPTR_TYPEDEF(IWbemClassObject, __uuidof(IWbemClassObject));

struct CComError
{
	HRESULT hr;
	const char *msg;
};

struct CCoInitializeEx
{
	HRESULT hr;
	CCoInitializeEx(DWORD dwCoInit)
	{
		hr = CoInitializeEx(nullptr, dwCoInit);
	}
	~CCoInitializeEx()
	{
		if (SUCCEEDED(hr))
			CoUninitialize();
	}
};

#define HRCHECK(what, msg) { HRESULT hr = what; if FAILED(hr) throw CComError { hr, msg }; }

int main(int argc, char* argv[])
{
	setlocale(LC_CTYPE, ".ACP");

	wchar_t pszName[CREDUI_MAX_USERNAME_LENGTH + 1] = L"user";
	wchar_t pszPwd[CREDUI_MAX_PASSWORD_LENGTH + 1] = L"password";
	BSTR strNetworkResource;
	//To use a WMI remote connection set localconn to false and configure the values of the pszName, pszPwd and the name of the remote machine in strNetworkResource
	bool localconn = true;
	strNetworkResource = localconn ? L"\\\\.\\root\\CIMV2" : L"\\\\remote--machine\\root\\CIMV2";

	COAUTHIDENTITY *userAcct = NULL;
	COAUTHIDENTITY authIdent;

	HRESULT hres;

	try
	{
		// Initialize COM. ------------------------------------------

		CCoInitializeEx coinit(COINIT_MULTITHREADED);
		HRCHECK(coinit.hr, "Failed to initialize COM library.");

		// Set general COM security levels --------------------------

		DWORD impLevel = localconn ? RPC_C_IMP_LEVEL_IMPERSONATE : RPC_C_IMP_LEVEL_IDENTIFY;

		hres = CoInitializeSecurity(
			NULL,
			-1,                          // COM authentication
			NULL,                        // Authentication services
			NULL,                        // Reserved
			RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication
			impLevel,					 // Default Impersonation
			NULL,                        // Authentication info
			EOAC_NONE,                   // Additional capabilities
			NULL                         // Reserved
			);
		HRCHECK(hres, "Failed to initialize security.");

		// Obtain the initial locator to WMI -------------------------

		IWbemLocatorPtr pLoc;
		hres = pLoc.CreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER);
		HRCHECK(hres, "Failed to create IWbemLocator object.");

		// Connect to WMI through the IWbemLocator::ConnectServer method

		IWbemServicesPtr pSvc;

		if (localconn)
			hres = pLoc->ConnectServer(
			_bstr_t(strNetworkResource),      // Object path of WMI namespace
			NULL,                    // User name. NULL = current user
			NULL,                    // User password. NULL = current
			0,                       // Locale. NULL indicates current
			NULL,                    // Security flags.
			0,                       // Authority (e.g. Kerberos)
			0,                       // Context object
			&pSvc                    // pointer to IWbemServices proxy
			);
		else
			hres = pLoc->ConnectServer(
			_bstr_t(strNetworkResource),  // Object path of WMI namespace
			_bstr_t(pszName),             // User name
			_bstr_t(pszPwd),              // User password
			NULL,                // Locale
			NULL,                // Security flags
			NULL,                 // Authority
			NULL,                // Context object
			&pSvc                // IWbemServices proxy
			);
		HRCHECK(hres, "Could not connect.");

		cout << "Connected to root\\CIMV2 WMI namespace" << endl;

		// Set security levels on the proxy -------------------------
		if (localconn)
			hres = CoSetProxyBlanket(
			pSvc,                        // Indicates the proxy to set
			RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
			RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
			NULL,                        // Server principal name
			RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx
			RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
			NULL,                        // client identity
			EOAC_NONE                    // proxy capabilities
			);
		else
		{
			// Create COAUTHIDENTITY that can be used for setting security on proxy
			memset(&authIdent, 0, sizeof(COAUTHIDENTITY));
			authIdent.PasswordLength = wcslen(pszPwd);
			authIdent.Password = (USHORT*)pszPwd;
			authIdent.User = (USHORT*)pszName;
			authIdent.UserLength = wcslen(pszName);
			authIdent.Domain = 0;
			authIdent.DomainLength = 0;
			authIdent.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
			userAcct = &authIdent;

			hres = CoSetProxyBlanket(
				pSvc,                           // Indicates the proxy to set
				RPC_C_AUTHN_DEFAULT,            // RPC_C_AUTHN_xxx
				RPC_C_AUTHZ_DEFAULT,            // RPC_C_AUTHZ_xxx
				COLE_DEFAULT_PRINCIPAL,         // Server principal name
				RPC_C_AUTHN_LEVEL_PKT_PRIVACY,  // RPC_C_AUTHN_LEVEL_xxx
				RPC_C_IMP_LEVEL_IMPERSONATE,    // RPC_C_IMP_LEVEL_xxx
				userAcct,                       // client identity
				EOAC_NONE                       // proxy capabilities
				);
		}
		HRCHECK(hres, "Could not set proxy blanket.");

		// Use the IWbemServices pointer to make requests of WMI ----

		IEnumWbemClassObjectPtr pEnumerator;
		hres = pSvc->ExecQuery(L"WQL", L"SELECT * FROM Win32_NetworkAdapterConfiguration",
			WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
		HRCHECK(hres, "ExecQuery failed");

		// Secure the enumerator proxy
		if (!localconn)
		{
			hres = CoSetProxyBlanket(
				pEnumerator,                    // Indicates the proxy to set
				RPC_C_AUTHN_DEFAULT,            // RPC_C_AUTHN_xxx
				RPC_C_AUTHZ_DEFAULT,            // RPC_C_AUTHZ_xxx
				COLE_DEFAULT_PRINCIPAL,         // Server principal name
				RPC_C_AUTHN_LEVEL_PKT_PRIVACY,  // RPC_C_AUTHN_LEVEL_xxx
				RPC_C_IMP_LEVEL_IMPERSONATE,    // RPC_C_IMP_LEVEL_xxx
				userAcct,                       // client identity
				EOAC_NONE                       // proxy capabilities
				);
			HRCHECK(hres, "Could not set proxy blanket on enumerator.");
		}

		while (pEnumerator)
		{
			// Get the data from the WQL sentence
			IWbemClassObjectPtr pclsObj;
			ULONG uReturn = 0;

			HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);

			if (0 == uReturn || FAILED(hr))
				break;

			_variant_t vtProp;

			hr = pclsObj->Get(L"IPAddress", 0, &vtProp, 0, 0);// String
			if (SUCCEEDED(hr))
			{
				if (vtProp.vt == VT_NULL)
					wcout << "IPAddress : NULL" << endl;
				else if (vtProp.vt == VT_EMPTY)
					wcout << "IPAddress : EMPTY" << endl;
				else if ((vtProp.vt & VT_ARRAY))
				{

					SAFEARRAY *psa = vtProp.parray;
					if (psa)
					{
						LONG uBound = -1, lBound = 0;
						SafeArrayGetUBound(psa, 1, &uBound);
						SafeArrayGetLBound(psa, 1, &lBound);
						int nCount = uBound - lBound + 1;
						for (long i = 0; i < nCount; ++i)
						{
							BSTR element;
							SafeArrayGetElement(psa, &i, &element);
							wcout << element << endl;
						}
					}
				}
				else
					wcout << "IPAddress : " << vtProp.bstrVal << endl;
			}
		}

		// Cleanup
		return 0;   // Program successfully completed.
	}
	catch (CComError err)
	{
		cout << err.msg << " Error code = 0x" << hex << err.hr << endl;
		wcout << _com_error(err.hr).ErrorMessage() << endl;
		cout << "press enter to exit" << endl;
		cin.get();
		return 1;                  // Program has failed.
	}
}
Kliknij, aby dodać treść...

Pomoc 1.18.8

Typografia

Edytor obsługuje składnie Markdown, w której pojedynczy akcent *kursywa* oraz _kursywa_ to pochylenie. Z kolei podwójny akcent **pogrubienie** oraz __pogrubienie__ to pogrubienie. Dodanie znaczników ~~strike~~ to przekreślenie.

Możesz dodać formatowanie komendami , , oraz .

Ponieważ dekoracja podkreślenia jest przeznaczona na linki, markdown nie zawiera specjalnej składni dla podkreślenia. Dlatego by dodać podkreślenie, użyj <u>underline</u>.

Komendy formatujące reagują na skróty klawiszowe: Ctrl+B, Ctrl+I, Ctrl+U oraz Ctrl+S.

Linki

By dodać link w edytorze użyj komendy lub użyj składni [title](link). URL umieszczony w linku lub nawet URL umieszczony bezpośrednio w tekście będzie aktywny i klikalny.

Jeżeli chcesz, możesz samodzielnie dodać link: <a href="link">title</a>.

Wewnętrzne odnośniki

Możesz umieścić odnośnik do wewnętrznej podstrony, używając następującej składni: [[Delphi/Kompendium]] lub [[Delphi/Kompendium|kliknij, aby przejść do kompendium]]. Odnośniki mogą prowadzić do Forum 4programmers.net lub np. do Kompendium.

Wspomnienia użytkowników

By wspomnieć użytkownika forum, wpisz w formularzu znak @. Zobaczysz okienko samouzupełniające nazwy użytkowników. Samouzupełnienie dobierze odpowiedni format wspomnienia, zależnie od tego czy w nazwie użytkownika znajduje się spacja.

Znaczniki HTML

Dozwolone jest używanie niektórych znaczników HTML: <a>, <b>, <i>, <kbd>, <del>, <strong>, <dfn>, <pre>, <blockquote>, <hr/>, <sub>, <sup> oraz <img/>.

Skróty klawiszowe

Dodaj kombinację klawiszy komendą notacji klawiszy lub skrótem klawiszowym Alt+K.

Reprezentuj kombinacje klawiszowe używając taga <kbd>. Oddziel od siebie klawisze znakiem plus, np <kbd>Alt+Tab</kbd>.

Indeks górny oraz dolny

Przykład: wpisując H<sub>2</sub>O i m<sup>2</sup> otrzymasz: H2O i m2.

Składnia Tex

By precyzyjnie wyrazić działanie matematyczne, użyj składni Tex.

<tex>arcctg(x) = argtan(\frac{1}{x}) = arcsin(\frac{1}{\sqrt{1+x^2}})</tex>

Kod źródłowy

Krótkie fragmenty kodu

Wszelkie jednolinijkowe instrukcje języka programowania powinny być zawarte pomiędzy obróconymi apostrofami: `kod instrukcji` lub ``console.log(`string`);``.

Kod wielolinijkowy

Dodaj fragment kodu komendą . Fragmenty kodu zajmujące całą lub więcej linijek powinny być umieszczone w wielolinijkowym fragmencie kodu. Znaczniki ``` lub ~~~ umożliwiają kolorowanie różnych języków programowania. Możemy nadać nazwę języka programowania używając auto-uzupełnienia, kod został pokolorowany używając konkretnych ustawień kolorowania składni:

```javascript
document.write('Hello World');
```

Możesz zaznaczyć również już wklejony kod w edytorze, i użyć komendy  by zamienić go w kod. Użyj kombinacji Ctrl+`, by dodać fragment kodu bez oznaczników języka.

Tabelki

Dodaj przykładową tabelkę używając komendy . Przykładowa tabelka składa się z dwóch kolumn, nagłówka i jednego wiersza.

Wygeneruj tabelkę na podstawie szablonu. Oddziel komórki separatorem ; lub |, a następnie zaznacz szablonu.

nazwisko;dziedzina;odkrycie
Pitagoras;mathematics;Pythagorean Theorem
Albert Einstein;physics;General Relativity
Marie Curie, Pierre Curie;chemistry;Radium, Polonium

Użyj komendy by zamienić zaznaczony szablon na tabelkę Markdown.

Lista uporządkowana i nieuporządkowana

Możliwe jest tworzenie listy numerowanych oraz wypunktowanych. Wystarczy, że pierwszym znakiem linii będzie * lub - dla listy nieuporządkowanej oraz 1. dla listy uporządkowanej.

Użyj komendy by dodać listę uporządkowaną.

1. Lista numerowana
2. Lista numerowana

Użyj komendy by dodać listę nieuporządkowaną.

* Lista wypunktowana
* Lista wypunktowana
** Lista wypunktowana (drugi poziom)

Składnia Markdown

Edytor obsługuje składnię Markdown, która składa się ze znaków specjalnych. Dostępne komendy, jak formatowanie , dodanie tabelki lub fragmentu kodu są w pewnym sensie świadome otaczającej jej składni, i postarają się unikać uszkodzenia jej.

Dla przykładu, używając tylko dostępnych komend, nie możemy dodać formatowania pogrubienia do kodu wielolinijkowego, albo dodać listy do tabelki - mogłoby to doprowadzić do uszkodzenia składni.

W pewnych odosobnionych przypadkach brak nowej linii przed elementami markdown również mógłby uszkodzić składnie, dlatego edytor dodaje brakujące nowe linie. Dla przykładu, dodanie formatowania pochylenia zaraz po tabelce, mogłoby zostać błędne zinterpretowane, więc edytor doda oddzielającą nową linię pomiędzy tabelką, a pochyleniem.

Skróty klawiszowe

Skróty formatujące, kiedy w edytorze znajduje się pojedynczy kursor, wstawiają sformatowany tekst przykładowy. Jeśli w edytorze znajduje się zaznaczenie (słowo, linijka, paragraf), wtedy zaznaczenie zostaje sformatowane.

  • Ctrl+B - dodaj pogrubienie lub pogrub zaznaczenie
  • Ctrl+I - dodaj pochylenie lub pochyl zaznaczenie
  • Ctrl+U - dodaj podkreślenie lub podkreśl zaznaczenie
  • Ctrl+S - dodaj przekreślenie lub przekreśl zaznaczenie

Notacja Klawiszy

  • Alt+K - dodaj notację klawiszy

Fragment kodu bez oznacznika

  • Alt+C - dodaj pusty fragment kodu

Skróty operujące na kodzie i linijkach:

  • Alt+L - zaznaczenie całej linii
  • Alt+, Alt+ - przeniesienie linijki w której znajduje się kursor w górę/dół.
  • Tab/⌘+] - dodaj wcięcie (wcięcie w prawo)
  • Shit+Tab/⌘+[ - usunięcie wcięcia (wycięcie w lewo)

Dodawanie postów:

  • Ctrl+Enter - dodaj post
  • ⌘+Enter - dodaj post (MacOS)