-
June 3rd, 2002, 07:19 AM
#1
Win32_NetworkAdapterConfiguration
Hi All,
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
Cherian
-
June 3rd, 2002, 08:20 AM
#2
Hi,
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?
David
-
June 3rd, 2002, 08:41 AM
#3
Hi David,
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.
Thanks
Cherian
-
June 3rd, 2002, 09:16 AM
#4
Hi David,
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.
Thanks
Cherian
-
June 4th, 2002, 12:54 AM
#5
Hi,
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
or
netsh interface ip set address "Local Area Connection" dhcp – it enables the DHCP
You can run this command by CreateProccess(…) etc.
More info:
http://support.microsoft.com/default...;EN-US;q242468
David
-
June 4th, 2002, 01:18 AM
#6
Hi David,
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.
Thanks
Cherian
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 )
MessageBox("SpawnInstance Success");
else
MessageBox("SpawnInstance Failed");*/
// Call the method.
hr = pNamespace->ExecMethod(ClassPath, MethodName, 0, NULL,
NULL, &pOutInst, NULL);
-
June 4th, 2002, 02:02 AM
#7
Hi,
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:
Code:
Dim nRet, AdapterConfig, nNicNr
nNicNr = 0
Set AdapterConfig = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & nNicNr)
nRet = AdapterConfig.EnableDHCP
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++.
David
-
June 4th, 2002, 03:59 AM
#8
Hi,
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
Thanks
Cherian
-
June 4th, 2002, 04:19 AM
#9
No, I haven't C++ code which solves this problem. The code you wrote I tried too and with the same result.
Regards,
David
-
June 4th, 2002, 05:15 AM
#10
Using WMI
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
HRESULT hres;
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?
Thanks
-
June 4th, 2002, 05:36 AM
#11
Hi,
I tried with CoInitialize and it passed in
Win2000 SP2 machine.
rgds
Cherian
-
June 4th, 2002, 05:48 AM
#12
If you want to use CoInitializeEx(0, COINIT_MULTITHREADED); you must define the following:
#define _WIN32_DCOM
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.
David
-
June 8th, 2002, 05:59 AM
#13
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.
Cherian,
What did you defined and where?
Please reply I really need it.
Thanks
Sharon
-
June 8th, 2002, 07:44 AM
#14
I defined it in the preprocessor definitions only.
-
December 12th, 2013, 09:14 PM
#15
Re: Win32_NetworkAdapterConfiguration
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|