示例#1
0
 private static extern int WNetUseConnection(
     IntPtr hwndOwner,
     Netresource lpNetResource,
     string lpPassword,
     string lpUserId,
     int dwFlags,
     string lpAccessName,
     string lpBufferSize,
     string lpResult
     );
示例#2
0
    /// <summary>
    /// Connects to the remote share
    /// </summary>
    /// <returns>Null if successful, otherwise error message.</returns>
    public static string ConnectToShare(string uri, string username, string password)
    {
        //Create netresource and point it at the share
        var nr = new Netresource
        {
            dwType       = ResourcetypeDisk,
            lpRemoteName = uri
        };

        //Create the share
        var ret = WNetUseConnection(IntPtr.Zero, nr, password, username, 0, null, null, null);

        //Check for errors
        return(ret == NoError ? null : GetError(ret));
    }