Win32_NetworkAdapterConfiguration
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Win32_NetworkAdapterConfiguration

  1. #1
    Join Date
    May 2002
    Posts
    19

    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

  2. #2
    Join Date
    Jan 2002
    Location
    Czech
    Posts
    251
    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

  3. #3
    Join Date
    May 2002
    Posts
    19
    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

  4. #4
    Join Date
    May 2002
    Posts
    19
    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

  5. #5
    Join Date
    Jan 2002
    Location
    Czech
    Posts
    251
    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

  6. #6
    Join Date
    May 2002
    Posts
    19
    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);

  7. #7
    Join Date
    Jan 2002
    Location
    Czech
    Posts
    251
    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

  8. #8
    Join Date
    May 2002
    Posts
    19
    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

  9. #9
    Join Date
    Jan 2002
    Location
    Czech
    Posts
    251
    No, I haven't C++ code which solves this problem. The code you wrote I tried too and with the same result.

    Regards,
    David

  10. #10
    Join Date
    May 2002
    Posts
    25

    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

  11. #11
    Join Date
    May 2002
    Posts
    19
    Hi,
    I tried with CoInitialize and it passed in
    Win2000 SP2 machine.

    rgds
    Cherian

  12. #12
    Join Date
    Jan 2002
    Location
    Czech
    Posts
    251
    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

  13. #13
    Join Date
    May 2002
    Posts
    25
    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

  14. #14
    Join Date
    May 2002
    Posts
    19
    I defined it in the preprocessor definitions only.

  15. #15
    Join Date
    Dec 2013
    Posts
    5

    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?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center