remotely access the computer c#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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 i = 0; i < arr.Length; i++)
{
ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Username = "username";
connOptions.Password = "password";

ManagementScope scope = new ManagementScope(("\\" + arr + "\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"]);
// Console.ReadKey();
}
}
catch (Exception exp)
{
Console.WriteLine("Exception while querying " + arr + ". Exception is " + exp.Message);
}
}

Console.WriteLine("done");

Console.ReadKey();
}
}
in the above code im try to access remote computers where i need to get client machine name as well as the windows directory but each time when i try to connect it im getting as ACCESS DENIED CODE ERROR 0X8007005 i have been logged in as an administrator
only can any one help me out with this problem
thank you
woody halls


View the full article
 
Back
Top