المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Connections options in C#



C# Programming
01-21-2010, 11:21 AM
Hi,
In my program i'm trying to access a server drives details from my machine with different username and password, for this i'm using the connections options class in C#,
here is the code i'm using

try
{
ConnectionOptions opt = new ConnectionOptions("MS_409", "USERNAME", "PASSWORD", "ntdlmdomain:DOMAIN", ImpersonationLevel.Impersonate, AuthenticationLevel.Default,false, null, TimeSpan.MaxValue);
ObjectQuery query = new ObjectQuery("SELECT FreeSpace, Name FROM Win32_LogicalDisk WHERE DriveType = 3");
ManagementScope scope = new ManagementScope("\\\\" + "16.106.64.108" + "\\root\\cimv2", opt);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection coll = searcher.Get();

foreach (ManagementObject ms in coll)
{
Console.WriteLine(ms["Name"]);
Console.WriteLine(Convert.ToDecimal(ms["FreeSpace"]) / 1024 / 1024 / 1024);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}

whenever i reach line "ManagementObjectCollection coll = searcher.Get();" i'm getting the "Invalid Parameter" error, i could not find a slution for this, please help.

Thanks,
D.Vinoth :(