[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how do solve access denied error code 0x80070005?

Posted on 2011-02-24
8
Medium Priority
?
1,151 Views
Last Modified: 2013-12-17

Hi all

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
using System.Net;
using System.Management;
using System.Diagnostics;

public class Program
{
    static void Main(string[ ] args)
    {

            string[] arr = { "10.10.10.53" };//,"10.10.10.10","10.10.10.34","10.10.10.49", "10.10.10.40", "10.10.10.56", "10.10.10.27", "10.10.10.55", "10.10.10.15", "10.10.10.64", "10.10.10.68", "10.10.10.52", "10.10.10.54", "10.10.10.41", "10.10.10.70", "10.10.10.33" };
            for (int index = 0; index < arr.Length; index++)
            {

                ConnectionOptions connOptions = new ConnectionOptions();
                connOptions.Username = "jaMochaHQ\adstest";
                connOptions.Password = "adstest321";
                ManagementScope scope = new ManagementScope(("\\\\" + arr[index] + "\\root\\cimv2"), connOptions);
             
               //scope.Connect();
               //scope.Options.EnablePrivileges = true;
               //scope.Options.Impersonation = System.Management.ImpersonationLevel.Impersonate;
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
               ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);          
            try
            {
                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    Console.WriteLine("Computer Name : {0}", m["csname"]);
                    Console.WriteLine("Windows Directory : {0}", m["WindowsDirectory"]);
                   
                }
           }
            catch (Exception exp)
            {
                Console.WriteLine("Exception while querying " + arr[index] + ". Exception is " + exp.Message);
            }
       }

        Console.WriteLine("done");

        Console.ReadKey();
    }
}
i have posted the code in which i'm try to access remote computers where i need to get client machine name as well as the windows directory  which returns me ACCESS DENIED ERROR CODE 0x80070005 when ever i execute it i have been logged in as domain administrator but still i'm not able to connect it can anyone help me out with this problem
0
Comment
Question by:sathish_raos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 29

Expert Comment

by:pwindell
ID: 34987427
If I uderstand what this is doing here,...it really doesn't matter what you are logged in as when you run it.  The script is creating a connection and using hardcoded credentials,...and it is those credentials that are failing:

               connOptions.Username = "jaMochaHQ\adstest";
               connOptions.Password = "adstest321";

I don't "write code" but this is what looks like is happening to me.
0
 
LVL 15

Accepted Solution

by:
Russell_Venable earned 200 total points
ID: 34989276
Your not including the domain in your credentials for the login. Try this instead.

using System;
using System.Management;

public class RemoteConnect
{
    public static void Main()
    {
        string[] arr = { "10.10.10.53","10.10.10.10","10.10.10.34","10.10.10.49", "10.10.10.40", "10.10.10.56", "10.10.10.27", "10.10.10.55", "10.10.10.15", "10.10.10.64", "10.10.10.68", "10.10.10.52", "10.10.10.54", "10.10.10.41", "10.10.10.70", "10.10.10.33" };

        for (int index = 0; index < arr.Length; index++)
        {
            ConnectionOptions connOptions = new ConnectionOptions();
            connOptions.Username = "jaMochaHQ\adstest";
            connOptions.Password = "adstest321";
            connOptions.Authority = "ntdlmdomain:" + arr[index];

            ManagementScope scope = new ManagementScope("\\\\" + arr[index] + "\\root\\cimv2", connOptions);
            scope.Connect();

            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            try
            {
                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    Console.WriteLine("Computer Name : {0}", m["csname"]);
                    Console.WriteLine("Windows Directory : {0}", m["WindowsDirectory"]);
                    Console.WriteLine("Operating System: {0}", m["Caption"]);

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception while querying " + arr[index] + ". Exception is " + ex.Message);
            }
        }
    }
}

Open in new window

0
 

Author Comment

by:sathish_raos
ID: 34994700
Thanks for the reply.
But still i'm getting the exception as :Exception while querying 10.10.10.53.Exception is invalid parameter. can anyone help me out.
Thanks,
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 15

Expert Comment

by:Russell_Venable
ID: 34995167
You might change the csname to Csname.
0
 

Author Comment

by:sathish_raos
ID: 34996007
thank you for the replay but the error is still the same :Exception while querying 10.10.10.53.Exception is invalid parameter. can anyone help me out

thanks
0
 
LVL 15

Expert Comment

by:Russell_Venable
ID: 34999993
Ok so the problem is different now, correct? No longer a access denied?
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
Here's a look at newsworthy articles and community happenings during the last month.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question