Results 1 to 2 of 2

Thread: Operation requires elevation, but already running as admin?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,708

    Operation requires elevation, but already running as admin?

    So I'm writing a shortcut program that mimics some of the functionality of the Network Connections box for LAN connections... Disable and Enable, which also have the elevation shield in Windows, work fine. But Rename returns 0x800702E4 The requested operation requires elevation. The result is the same both in the IDE, which is marked to run as admin, and when the program is compiled and explicitly right-clicked and 'Run As Admin'.
    I've encountered plenty of times where even my 'Administrator' account is told it doesn't have permission to blah blah blah, but that's usually also what Explorer reports. But here, I *can* rename the selected connection in Explorer. And the method I'm using is the direct network connection COM interfaces which theoretically should function exactly the same as Explorer, making this even odder (INetworkConnection).
    Can anyone offer some insight as to why this would happen and how I can correct it?

    It's a simple 1 line code, and the disable/enable commands are on the same object, so there doesn't seem to be much opportunity for screwup when those are working...

    Debug.Print Hex$(pNetCons(idx).Rename(StrPtr(Text1.Text)))


    The object is set like this:

    Code:
    Private pConMgr     As ConnectionManager
    Private pNetCons()  As INetConnection
    Private nCons       As Long
    Private Declare Function SysReAllocString Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long) As Long
    Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal PV As Long) ' Frees memory allocated by the shell
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Sub NcFreeNetconProperties Lib "netshell.dll" (ByVal pProps As Long)
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const LB_SETHORIZONTALEXTENT = &H194
    
    Private Function LPWSTRtoStr(lPtr As Long, Optional ByVal fFree As Boolean = True) As String
    SysReAllocString VarPtr(LPWSTRtoStr), lPtr
    If fFree Then
        Call CoTaskMemFree(lPtr)
    End If
    End Function
    
    Private Sub Command1_Click()
    
        If pConMgr Is Nothing Then
            Set pConMgr = New ConnectionManager
        End If
        If pConMgr Is Nothing Then
            Debug.Print "Couldn't start connection manager."
            Exit Sub
        End If
    
    ReDim pNetCons(0)
    nCons = 0
    List1.Clear
        Dim pEnumCon  As IEnumNetConnection
        Dim pcl       As Long
        Dim tConProps As NETCON_PROPERTIES
        Dim szConDev  As String, szConName As String
        Dim lpnp      As Long
        Dim hrcon     As Long
        Dim pConTmp   As INetConnection
    
        pConMgr.EnumConnections NCME_DEFAULT, pEnumCon
    
        If (pEnumCon Is Nothing) = False Then
    
            Do While (pEnumCon.Next(1, pConTmp, pcl) = S_OK)
                ReDim Preserve pNetCons(nCons)
                Set pNetCons(nCons) = pConTmp
                hrcon = pNetCons(nCons).GetProperties(lpnp)
                Debug.Print "GetProps hr=0x" & Hex$(hrcon)
    
                If lpnp Then
                    CopyMemory ByVal VarPtr(tConProps), ByVal lpnp, LenB(tConProps)
                Else
                    Debug.Print "Null pointer"
                    GoTo nxtcon
                End If
                szConName = LPWSTRtoStr(tConProps.pszwName, False)
                szConDev = LPWSTRtoStr(tConProps.pszwDeviceName, False)
                List1.AddItem "Device " & GetNETCON_MEDIATYPEStr(tConProps.MediaType) & ", " & szConName & "/" & szConDev & ", Status=" & GetNETCON_STATUSStr(tConProps.Status) & ", GUID=" & GUIDToString(tConProps.guidId)
                NcFreeNetconProperties lpnp
                nCons = nCons + 1
    nxtcon:
            Loop
        Else
            Debug.Print "Failed to get enumerator"
        End If
    
        Exit Sub
    
    End Sub
    (my oleexp typelib was updated earlier today with these interfaces for anyone else wanting to play around with it)

  2. #2
    Lively Member
    Join Date
    Sep 2016
    Posts
    94

    Re: Operation requires elevation, but already running as admin?

    Hi fafalone,

    'List1.AddItem "Device" & GetNETCON_MEDIATYPEStr (tConProps.MediaType) & "," & szConName & "/" & szConDev & ", Status =" & GetNETCON_STATUSStr (tConProps.Status) & ", GUID =" & GUIDToString.g )

    GetNETCON_MEDIATYPEStr > Err Undefined Function

Posting Permissions

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



Click Here to Expand Forum to Full Width