none
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) in vb.net RRS feed

  • Question

  • Hi,

    when try w3ith this code to access the remote computer

      Dim options As ConnectionOptions = New ConnectionOptions
                options.Username = "shambhuremote"
                options.Password = "tempPassword"
                options.Impersonation = ImpersonationLevel.Impersonate
                options.Authentication = AuthenticationLevel.Connect
                options.EnablePrivileges = True

                Dim path As ManagementPath = New ManagementPath("\\remote124\root\cimv2")
                Dim scope As ManagementScope = New ManagementScope(path, options)
                scope.Options.EnablePrivileges = True
                scope.Connect()
             
                Dim query As ObjectQuery
                query = New ObjectQuery("SELECT * FROM Win32_OperatingSystem")
                Dim searcher As ManagementObjectSearcher
                searcher = New ManagementObjectSearcher(scope, query)

                Dim queryCollection As ManagementObjectCollection
                queryCollection = searcher.Get()

                Dim m As ManagementObject
                For Each m In queryCollection
                    ' Display the remote computer information
                    Dim sRes As StringBuilder = New StringBuilder()

                    sRes.Append("Computer Name : {0}", m("csname"))
                    sRes.Append("Windows Directory : {0}", m("WindowsDirectory"))
                    sRes.Append("Operating System: {0}", m("Caption"))
                    sRes.Append("Version: {0}", m("Version"))
                    sRes.Append("Manufacturer : {0}", m("Manufacturer"))
                Next

    it is saying :System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

    scope.Connect() at this line i am getting the error.

    How to resolve this error.

    Wednesday, May 16, 2012 10:27 AM

Answers

  • Hi Shambhu,

    Thank you for posting on this forum.

    Please take a look at this documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394603(v=vs.85).aspx

    Access Denied

    Access Denied errors that are reported by scripts and applications that access WMI namespaces and data generally fall into three categories. The following table lists the three categories of errors along with issues that might cause the errors and possible solutions.

    Error Possible Issues Solution

    0x800706BA - RPC Server Unavailable

    Firewall issue or server not available.

    The computer really doesn't exist · The Windows Firewall is blocking the connection Connecting to Vista: netsh advfirewall firewall set rule group="windows management instrumentation (wmi)" new enable=yes Connecting to downlevel: Allow the "Remote Administration" rule in Windows Firewall.

    0x80070005 – E_ACCESS_DENIED

    Access denied by DCOM security.

    The user does not have remote access to the computer through DCOM. Typically, DCOM errors occur when connecting to a remote computer with a different operating system version. Give the user Remote Launch and Remote Activation permissions in dcomcnfg. Right-click My Computer-> Properties Under COM Security, click "Edit Limits" for both sections. Give the user you want remote access, remote launch, and remote activation. Then go to DCOM Config, find "Windows Management Instrumentation", and give the user you want Remote Launch and Remote Activation. For more information, see Connecting Between Different Operating Systems

    0x80041003 – WMI Access Denied

    Access denied by a provider

    The user does not have permission to perform the operation in WMI. This could happen when you query certain classes as a low-rights user, but most often happens when you attempt to invoke methods or change WMI instances as a low rights user. The namespace you are connecting to is encrypted, and the user is attempting to connect with an unencrypted connection Give the user access with the WMI Control (make sure they have Remote_Access set to true) Connect using a client that supports encryption.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, May 17, 2012 8:16 AM
    Moderator

All replies

  • Hi,

    It is a security rights issue, you need to contact your administrator and find out you had respective privileges to access your remote server through your code. Remember accessing from explorer is different from having privileges to access from your source code.


    Sai Kumar K http://www.santoshtechnologies.com http://saimaterial.wordpress.com

    Wednesday, May 16, 2012 10:53 AM
  • I have contacted the admin, they are saying, this computer is able to take remote machine, this system is able to open shared folder on network server, so what other permission is needed, if they are how to do it.
    Wednesday, May 16, 2012 11:13 AM
  • Check out this: http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/cbd93b81-2c23-4363-a00e-f702d6fa1349


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Wednesday, May 16, 2012 11:14 AM
  • I have tried those suggestion but no positive result is there. there must be a setting or anything in code that i am missing otherwise how this code will published from microsoft.

    Wednesday, May 16, 2012 11:18 AM
  • Hi, 

    It definitely , error code, saying cant't allow you connect.

    You can use WMI Administrator tool to debug the issue, can download from 

    http://www.microsoft.com/en-us/download/details.aspx?id=24045

    I hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    Wednesday, May 16, 2012 1:24 PM
  • Hi Shambhu,

    Please try below steps:

    • Run dcomcnfg to bring up Component Services window.
    • Expand Component Services > Computers > My Computer > DCOM Config
    • Scroll down list, right click Windows Management and Instrumentation, and select properties.  A 5 tabbed window named Windows Management and Instrumentation Properties should be displayed.
    • Select the Security tab, then select radio buttons which activate the Edit... buttons.
    • Select the appropriate location and add the ASPNET account.
    • Reboot.

    You should be good to go.


    Regards, http://shwetamannjain.blogspot.com


    Thursday, May 17, 2012 3:27 AM
  • Hi Shambhu,

    Thank you for posting on this forum.

    Please take a look at this documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394603(v=vs.85).aspx

    Access Denied

    Access Denied errors that are reported by scripts and applications that access WMI namespaces and data generally fall into three categories. The following table lists the three categories of errors along with issues that might cause the errors and possible solutions.

    Error Possible Issues Solution

    0x800706BA - RPC Server Unavailable

    Firewall issue or server not available.

    The computer really doesn't exist · The Windows Firewall is blocking the connection Connecting to Vista: netsh advfirewall firewall set rule group="windows management instrumentation (wmi)" new enable=yes Connecting to downlevel: Allow the "Remote Administration" rule in Windows Firewall.

    0x80070005 – E_ACCESS_DENIED

    Access denied by DCOM security.

    The user does not have remote access to the computer through DCOM. Typically, DCOM errors occur when connecting to a remote computer with a different operating system version. Give the user Remote Launch and Remote Activation permissions in dcomcnfg. Right-click My Computer-> Properties Under COM Security, click "Edit Limits" for both sections. Give the user you want remote access, remote launch, and remote activation. Then go to DCOM Config, find "Windows Management Instrumentation", and give the user you want Remote Launch and Remote Activation. For more information, see Connecting Between Different Operating Systems

    0x80041003 – WMI Access Denied

    Access denied by a provider

    The user does not have permission to perform the operation in WMI. This could happen when you query certain classes as a low-rights user, but most often happens when you attempt to invoke methods or change WMI instances as a low rights user. The namespace you are connecting to is encrypted, and the user is attempting to connect with an unencrypted connection Give the user access with the WMI Control (make sure they have Remote_Access set to true) Connect using a client that supports encryption.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, May 17, 2012 8:16 AM
    Moderator
  • I have the exact same error trying to do the exact same thing. The problem is it works fine against another computer, but another throws this error. They are all windows 2008 servers.

    The code works against many other systems, just this one, I keep getting this error using the administrator login. Not sure why.

    Monday, March 18, 2013 11:17 PM
  • This is in C# but the same thing, I got it to work. In windows 7 where I'm running the program, I added a windows credential.

    Start -> Control Panel -> Credential Manager

    Add one for the computer you are trying to access, a credential that has access.

    Monday, March 18, 2013 11:57 PM
  • I think that the error usually occurs without calling CoInitializeSecurity.

    Thursday, May 28, 2015 2:48 AM
  • Hi Mike,

    I know this is an old post, but having same issue in VS2015 when trying to load the designer. I found your solution useful but am still not quite sure which items I should tick. I've pasted below in yellow highlight my concerns -- some may not pertain to this, so just ignore.

    Windows 10 system.

    Any help is much appreciated ... thanks....

    IMAGE 1

    IMAGE 2


    Newbie enough to get myself into trouble. :0)





    • Edited by GeneralB Wednesday, January 11, 2017 9:17 PM
    Wednesday, January 11, 2017 9:14 PM