Справочник по C#

    Исходники по языку программирования CSharp

    Список подключенных дисков: Справочник по C#

    /
    /
    /
    118 Views


    /// 
    /// method for retrieving all mapped drives
    /// 
    /// 
    public List GetMappedDriveList(string machine, string username, string pwd)
    {
    try
    {
    List drives = new List();
    
    ConnectionOptions options = new ConnectionOptions();
    options.Username = username;
    options.Password = pwd;
    options.Impersonation = ImpersonationLevel.Impersonate;
    
    ManagementPath path = new ManagementPath(@"\" + machine + @"rootcimv2");
    
    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)
    {
    MessageBox.Show(string.Format("Error retrieving mapped drives: {0}", ex.Message), "Mapped Drives", MessageBoxButtons.OK, MessageBoxIcon.Error);
    return null;
    }
    }

    Взято с http://www.dreamincode.net

    Список подключенных дисков: Справочник по C#

    0.00 (0%) 0 votes

    moyadcode13
    • Facebook
    • Twitter
    • Google+
    • Linkedin
    • Pinterest