Esempio n. 1
0
    /// <summary>
    /// Deletes a mapped drive
    /// </summary>
    /// <param name="Drive"></param>
    /// <returns></returns>
    public static Option <DriveLetter> UnMap(this DriveLetter Drive)
    {
        var result = WNetCancelConnection2(Drive.ToString(), ConnectionFlags.CONNECT_UPDATE_PROFILE, false);

        return
            (result == ErrorCodes.ERROR_SUCCESS
                    ? some(Drive)
                    : none <DriveLetter>(error("WinAPI call failed")));
    }
Esempio n. 2
0
    /// <summary>
    /// Maps a drive letter to a UNC path
    /// </summary>
    /// <param name="Drive">The drive to map</param>
    /// <param name="UncPath">The unc path to assign to the drive</param>
    /// <remarks>
    /// Adapted from http://www.blackwasp.co.uk/MapDriveLetter.aspx
    /// </remarks>
    public static Option <DriveMount> Map(this DriveLetter Drive, string UncPath, string UserName = null, string UserPass = null)
    {
        var networkResource = new NETRESOURCE();

        networkResource.dwType       = RESOURCETYPE_DISK;
        networkResource.lpLocalName  = Drive.ToString();
        networkResource.lpRemoteName = UncPath;
        networkResource.lpProvider   = null;
        var result = WNetAddConnection2(ref networkResource, UserName, UserPass, ConnectionFlags.CONNECT_UPDATE_PROFILE);

        return
            (result == ErrorCodes.ERROR_SUCCESS
                    ? some(new DriveMount(Drive))
                    : none <DriveMount>(error("WinAPI call failed")));
    }