Error 0x80070005 when using SWbemLocator.ConnectServer to initiate a WMI session despite using the correct username and password

System Requirements:

  • WMI 1.5 or higher
  • Windows 95, 98, 98SE, Millennium
  • Windows NT 4.0, 2000, XP, 2003, Vista, 2008, 7

The Problem:

When using WMI’s SWbemLocator.ConnectServer class to log onto a remote system, you receive an 0x80070005 access denied error (Decimal -2147024891).

This error occurs even though the username and password are correct and the account credentials are synchronised properly between the local and remote machine – either by domain or manually in a workgroup.

More Info

The classfull connection line for using SWbemLocator is:

Set objWMIService = objSWbemLocator.ConnectServer(<computerName>, <wmiDefaultClassPath>, <username>, <password>)

for example:

Set objWMIService = objSWbemLocator.ConnectServer(“192.168.0.100”, “root\cimv2”, “Administrator”, “12345abcde”)

The Fix

There is a very good chance that the problem you are having is to do with the username you are entering. You need to ensure that you are prefixing the username with the logon domain.

For example if your domain is camie.local your username should be camie\Administrator

Set objWMIService = objSWbemLocator.ConnectServer(“192.168.0.100”, “root\cimv2”, “camie\Administrator”, “12345abcde”)

But I’m using a workgroup!

Don’t worry, you can do one of three things.

  1. Prefix the remote machine name (the local logon domain)
  2. Prefix the workgroup
  3. Send a null logon domain

Set objWMIService = objSWbemLocator.ConnectServer(“192.168.0.100”, “root\cimv2”, “myHostName\Administrator”, “12345abcde”)

 

Set objWMIService = objSWbemLocator.ConnectServer(“192.168.0.100”, “root\cimv2”, “workgroup\Administrator”, “12345abcde”)

 

Set objWMIService = objSWbemLocator.ConnectServer(“192.168.0.100”, “root\cimv2”, “\Administrator”, “12345abcde”)

Using one of the above, you should be able to connect to the remote workstation. If you are dealing with a mix of workgroups or cannot know the hostname in advance I suggest using \<username> with I have tested to work on Windows 95 right through to WIndows 7.