static List<string> GetMappedDriveList(string machine, string username, string pwd)
{
try
{
List<string> drives = new List<string>();
ConnectionOptions options = new ConnectionOptions();
options.Username = username;
options.Password = pwd;
options.Impersonation = ImpersonationLevel.Impersonate;
ManagementPath path = new ManagementPath(@"\\" + machine + @"\root\cimv2");
ObjectQuery query = new ObjectQuery("select * from Win32_MappedLogicalDisk");
ManagementScope scope = new ManagementScope(path, options);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
foreach (ManagementObject obj in searcher.Get())
drives.Add(obj.Properties["Name"].Value.ToString());
return drives;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
|