I
Wow!
Ich glaube ohne entsprechende Literatur ist das mit dem WMI nicht so leicht zu machen. Das erfordert schon mal sehr viel Vorarbeit bis man die eigentliche Methode überhaupt ausführen kann. Ganz zu schweigen davon, dass man erst mal das MS SDK runterladen muss, um die *.lib Dateien zu bekommen.
//COM initialisieren
HRESULT hres;
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres)){
Memo1->Lines->Add("Fehler: "+hres);
}
//COM Security setzen
hres = CoInitializeSecurity(
NULL, // Security descriptor
-1, // COM negotiates authentication service
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication level for proxies
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation level for proxies
NULL, // Authentication info
EOAC_NONE, // Additional capabilities of the client or server
NULL); // Reserved
if (FAILED(hres)){
Memo1->Lines->Add("Fehler: "+hres); // Program has failed.
}
//Verb. zum Namespace
IWbemLocator *pLoc = 0;
hres = CoCreateInstance(CLSID_WbemLocator, 0,
CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
if (FAILED(hres)){
Memo1->Lines->Add("Fehler: "+hres); // Program has failed.
CoUninitialize();
}
IWbemServices *pSvc = 0;
// Connect to the root\default namespace with the current user.
hres = pLoc->ConnectServer(L"ROOT\\cimv2", NULL, NULL, 0, NULL, 0, 0, &pSvc);
if (FAILED(hres)){
Memo1->Lines->Add("Fehler: "+hres); // Program has failed.
pLoc->Release();
CoUninitialize();
}
Memo1->Lines->Add("Mit WMI Verbunden"+hres);
// Set the proxy so that impersonation of the client occurs.
hres = CoSetProxyBlanket(pSvc,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE
);
if (FAILED(hres)){
Memo1->Lines->Add("Fehler: "+hres); // Program has failed.
pSvc->Release();
pLoc->Release();
CoUninitialize();
}
//Eigentliche Methoden
pSvc->ExecMethod("Win32_NetworkAdapterConfiguration",
...
);
Also ich bin daran gescheitert, dass ich nicht verstehe, wie man der eigentlichen Methode die InputParameter übergibt...
Ich muss kapitulieren