June 3rd, 2002, 07:19 AM
I have to use Win32_NetworkAdapterConfiguration class for getting/setting Network properties.
eg: For enabling DHCP. ( call the member function EnableDHCP() of this class.).
For this i need to use the COM interface IWbemLocator.
And this interface requires Wbemuuid.lib.
Although this Wbemuuid.lib is present in my machine, i couldn't find its coresponding dll in my machine.
So when i call CoCreateInstance it fails saying class is not registered.
My machine is Windows NT4 (SP6).
Please help me out of this problem.
I called CoCreateInstance like this.
CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLocator)
Thanks in Advance
June 3rd, 2002, 08:20 AM
I have the WBEM folder in the WinNT/System32 folder with a lot of WMIís DLLs. And on my computer the code works, but I have Win2000 SP2 and MS Platform SDK.
I wanted to use this class to change IP address but I havenít discovered how to use it. Do you know how to manipulate with the WMI classes?
June 3rd, 2002, 08:41 AM
I am also using the WMI functions for the first time.
I am using NT4 SP6 and MS Platform SDK.
According to MSDN it should work in my machine too.
If u could find any dll corresponding to Wbemuuid.lib please give me (may be its name will be Wbemuuid.dll ).
Please let me know if u could find a solution to ur IP Address problem.
June 3rd, 2002, 09:16 AM
I have tested the same code in Win2000, SP2, SDk and it worked.
Thankyou very much David...
Now i have to Enable/Disable the DHCP.
I would inform u if it is a success.
June 4th, 2002, 12:54 AM
I havenít solution about IP address with the WMI classes. I have only found the command line utility called Ďnetsh.exeĎ (as I mentioned in a different thread on this forum). You can run this command from the command line:
netsh interface ip set address "Local Area Connection" static 10.0.0.1 255.255.255.0 gateway=noneď Ė it changes the IP address
netsh interface ip set address "Local Area Connection" dhcp Ė it enables the DHCP
You can run this command by CreateProccess(Ö) etc.
June 4th, 2002, 01:18 AM
WMI classes should support this IP Address & DHCP. Isn't it.
But when i tried to Enable DHCP it failed.
Upto GetMethod() it returns SUCCESS but when i called
ExecMethod() it returned the error WBEM_E_INVALID_METHOD_PARAMETERS
Please let me know if u got it.
Following is my code.
IWbemLocator *pLocator = NULL;
IWbemServices *pNamespace = 0;
IWbemClassObject * pClass = NULL;
IWbemClassObject * pOutInst = NULL;
IWbemClassObject * pInClass = NULL;
IWbemClassObject * pInInst = NULL;
BSTR path = SysAllocString(L"root\\cimv2");
BSTR ClassPath = SysAllocString(L"Win32_NetworkAdapterConfiguration");
BSTR MethodName = SysAllocString(L"EnableDHCP");
hr = ::CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
IID_IWbemLocator, (LPVOID *) &pLocator);
hr = pLocator->ConnectServer(path, NULL, NULL, NULL, 0, NULL, NULL, &pNamespace);
// Get the class object for the method definition.
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);
// Get the input-argument class object and create an instance.
hr = pClass->GetMethod(MethodName, 0, &pInClass, NULL);
/* hr = pInClass->SpawnInstance(0, &pInInst);
if(hr == S_OK )
// Call the method.
hr = pNamespace->ExecMethod(ClassPath, MethodName, 0, NULL,
NULL, &pOutInst, NULL);
June 4th, 2002, 02:02 AM
I got the same error. I think, it is correct, because you should determine your network adapter. You only created the instance of the class, you didnít assigned the class to the adapter. Assume you have 3 network adapters in your computer and in your code you didnít determine which adapter you want to enable. The following short code in the basic works:
nNicNr is the number of my adapter and this adapter is assigned to Win32_NetÖ.. class. But my problem is I donít know how to assigned the adapter to the class. I donít know how to rewrite the stupid code to the C++.
Dim nRet, AdapterConfig, nNicNr
nNicNr = 0
Set AdapterConfig = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & nNicNr)
nRet = AdapterConfig.EnableDHCP
June 4th, 2002, 03:59 AM
I don't know how to assign the class to the adapter.
In the class name i gave it like this.
BSTR ClassPath = SysAllocString(L"Win32_NetworkAdapterConfiguration=0");
But GetObject itself is failing.
Let me know if u got the C++ code
June 4th, 2002, 04:19 AM
No, I haven't C++ code which solves this problem. The code you wrote I tried too and with the same result.
June 4th, 2002, 05:15 AM
I tried to use it too, for changing the IP address,
but I stocked in earlier stage.
Accordig to MSDN you should first Initialize COM.
When I tride to initiate the CON according to what they explained
in " http://msdn.microsoft.com/library/de...pprog_199b.asp
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
I get an error on: CoInitializeEx, undeclared identifiers
Although I have ole32.lib and I included "objbase.h".
Did you guys passed that stage?
June 4th, 2002, 05:36 AM
I tried with CoInitialize and it passed in
Win2000 SP2 machine.
June 4th, 2002, 05:48 AM
If you want to use CoInitializeEx(0, COINIT_MULTITHREADED); you must define the following:
Or you can add this statement to the project settings, preprocessor definitions.
Kojy: Did you receive my email about Netsh? Because I had a problem with the email.
June 8th, 2002, 05:59 AM
Hi David and Cherian ,
I tried to add _WIN32_DCOM to the project settings, preprocessor definitions, but it didn't worked.
In MSDN they say the I have to add the macros that specified my OS, for win2K it's _WIN32_WINNT=0x0500 and WINVER=0x0500
But it didn't worked either.
What did you defined and where?
Please reply I really need it.
June 8th, 2002, 07:44 AM
I defined it in the preprocessor definitions only.
December 12th, 2013, 08:14 PM
hr = pClass->GetMethod(MethodName, 0, &pInClass, NULL);
For any MethodName related to DHCP, this call returns S_OK, but pInClass is NULL. Any other method names documented for Win32_NetworkAdapterConfiguration are ok: returns with a valid pointer. I am running it on Windows 7.
Anyone has any clues of why?
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.