locked
INetConnection::Rename fails in Vista RRS feed

  • Question

  • Hi,
    I am trying to programmatic-ally change the display name of a network adapter in Vista 32-bit enterprise mode. I'm using the INetConnection::Rename() API. This works perfectly well in Windows XP. But it is failing in Vista !! I'm executing the program through Administrator command prompt to bypass UAC. The strange thing is that I am able to enable and disable the adapter using INetConnection::Connect() and INetConnection::Disconnect(), but Rename() method is not working. When I see the return code, it is not any of the valid return codes. Can someone throw a light on this?
    Friday, September 25, 2009 7:47 AM

All replies

  • Hello AVishnu

    Could you please share the HRESULT returned from INetConnection::Rename()?

    INetConnection::Rename requires administrative privilege on Windows Vista, thus the function needs to be run as administrator. For those tasks that need administrative privilege, the best practice is to put them into a seperate exe, and from your app launch the exe with "RunAs" shell command to perform the tasks. Here is an example:
    http://blogs.msdn.com/vistacompatteam/archive/2006/09/25/771232.aspx

    Also, from the MSDN doc
    http://msdn.microsoft.com/en-us/library/aa365099(VS.85).aspx
    Internet Connection Firewall may be altered or unavailable in subsequent versions. Instead, use the Windows Firewall API.
    However, as far as I know, Windows Firewall API for the above task requires elevation too.

    Thanks,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, September 25, 2009 10:52 AM
  • Hi,
    Thanks for your reply.
    The HRESULT I'm getting is 800702e4. When I did some search, this seems to be the result for 'Elevation required'.
    But I'm already running my executable in "RunAs" Administrator command prompt !! Also I got the same result when I launch the executable by "RunAs" in right-click.
    Its really strange.

    How do I use Windows Firewall APIs to achieve the same? I couldn't get the corresponding API.
    Friday, September 25, 2009 12:09 PM
  • It does not look like you need help compiling your code or using keywords. I would suggest you post in the Windows security programming forum at http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/threads.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    Friday, September 25, 2009 4:20 PM
  • Yes, error 0x800702e4 is a Windows error, ERROR_ELEVATION_REQUIRED.  Logging in as an administrator doesn't automatically give you elevated permissions anymore, UAC put a stop to that.  You'd have to put a manifest in your .exe that request the elevation.  Your customer will get the UAC prompt to ask for permission.  She'll likely stop clicking "Allow" after a while.  Although renaming an adapter isn't exactly a common thing to do.  Anyhoo, the manifest needs to contain this snippet:

      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
          <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
            <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
          </requestedPrivileges>
        </security>
      </trustInfo>




    Hans Passant.
    Friday, September 25, 2009 5:28 PM
  • Hi – I think my information can help:

    As, MSDN Library message said: [Internet Connection Firewall may be altered or unavailable in subsequent versions. Instead, use the Windows Firewall API.]

    Hmm? I am [not] aware if there might exist such function() call in the Windows Firewall API for this. The only Dynamic Link Library (DLL) that will provide you with INetConnection including its functions is the “hnetcfg.dll” or NetCon.h and for C# or VB it’s NETCONLib that should be used.


    Regarding the Windows Firewall API for such code actions, I do not think that the Windows Firewall API would be the best choice.

    #include <NetCon.h> //By including this, we can access INetConnection.

    I am not sure if you’re using it wrong, or maybe you just need as required a system buit-in admninstrator with high-previledges.  

    As Nobugz provided you with an app.manifest xml code-snippet, use that and the problem may be solved.

    Have a nice day…

    Best regards,
    Fisnik


    Coder24.com
    Saturday, September 26, 2009 11:47 AM
  • Hi,
      Thanks for all your feedback. I still was not able to successfully make use of the Rename() method of INetConnection interface in Vista. Somehow this looks to be a Vista bug to me. The same is the case with Win 7 also. But I am able to solve in a different way. I'm making use of Windows registry APIs to achieve the purpose. I'm posting the solution below.

    * Use RegOpenKeyEx to open the following registry key
     SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\<GUID_of_adapter>\\Connection

    * Use RegSetValue on 'Name' key to set the desired value.

    This solution worked perfectly on XP, Vista and Win 7.

    Hope MS will fix the INetConnection->rename() issue in the future support packs for Vista and Win 7.
    Wednesday, October 14, 2009 10:54 AM
  • Writing to HKLM would still fail if the process is not elevated. 

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    Wednesday, October 14, 2009 12:30 PM
  • That is what I'm claiming the bug to be. Please refer to the above replies. I'm trying to rename the network adapter from a system-level service which has the highest privilege (so there is no question of elevation). But even then, the Rename() method fails !! Where as the Connect() and Disconnect() methods work perfectly fine !! That is the bug !! Therefore I'm successfully able to write to HKLM. There is a problem only with the Rename() method.
    Wednesday, October 14, 2009 1:31 PM
  • Hi,

    I have written code for enabling /diabling the internet connection on Windows VISTA 32 bit enterprise mode. I am using INetConnection::Connect() and it fails when I execute the code under guest user. If I run the code under Admin user, it works fine. I have switched off the UAC.

    The return error code is 0x800702e4 which says " The requested operation requires an elevation."

    Can you please help me and tell that how did Connect method worked fine for you on Windows VISTA?

    Thanks

    IP

    Monday, November 15, 2010 1:04 PM
  • Hi AVishnu,

    I am facing the same issue on Windows 7 with Rename().

    I tried your fix (using registry APIs) which addressed the system crash at start up of the app but could not succeed to connect to wireless network once app is up.

    * Use RegOpenKeyEx to open the following registry key
     SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\<GUID_of_adapter>\\Connection

    * Use RegSetValue on 'Name' key to set the desired value.

    I appreciate your help in this regard.

    Thanks & Regards,

    Raam

    Monday, January 9, 2012 10:05 AM