Home All Groups Group Topic Archive Search About

managed API equivilent to WNetAddConnection

Author
26 Apr 2007 6:18 PM
Kristofor
Hi,

I'm wondering if there is a managed class/method that is equivilent to the
WNetAddConnection API.  I am writing an app that is required to connect to
various network resources without knowing whether those resources are
connected before hand.  I also need the functionality of being able to
provide profile/password information when attempting to access the network
resources.  So far I haven't found anything that will work, but if anyone
knows a way, I would appreciate hearing about it.  Thanks.

Kristofor

Author
27 Apr 2007 7:18 AM
Walter Wang [MSFT]
Hi Kristofor,

There's no equivalent managed API for WNetAddConnection. Using WNet* API in
.NET should be easy via P/Invoke.

What's your requirement here? Do you need a local drive letter to be mapped
to the network resource?

It's recommended to use WNetAddConnection2 over WNetAddConnection since the
latter is only provided for compatibility.

Since WNetAddConnection2 could connect to a network resource without
mapping to local drive letter, my suggestion is to try to access the
network resource first, if you can a Access Denied error, then try to
connect it with specified user/password.

Please see following thread for more information:

http://groups.google.com/group/microsoft.public.dotnet.framework.sdk/browse_
thread/thread/c2d1885859012e04/

http://groups.google.com/group/microsoft.public.dotnet.framework.sdk/browse_
thread/thread/7e4ef4494d9285bb/

Hope this helps.

Sincerely,
Walter Wang (waw***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
27 Apr 2007 4:54 PM
Kristofor
Thank you Walter.  I've done some work with P/Invoke before so I'm sure I can
manage it.  What you suggested was what I had in mind so thank you so much
for confirming it for me.

Regards,
  Kristofor

Show quote
"Walter Wang [MSFT]" wrote:

> Hi Kristofor,
>
> There's no equivalent managed API for WNetAddConnection. Using WNet* API in
> .NET should be easy via P/Invoke.
>
> What's your requirement here? Do you need a local drive letter to be mapped
> to the network resource?
>
> It's recommended to use WNetAddConnection2 over WNetAddConnection since the
> latter is only provided for compatibility.
>
> Since WNetAddConnection2 could connect to a network resource without
> mapping to local drive letter, my suggestion is to try to access the
> network resource first, if you can a Access Denied error, then try to
> connect it with specified user/password.
>
> Please see following thread for more information:
>
> http://groups.google.com/group/microsoft.public.dotnet.framework.sdk/browse_
> thread/thread/c2d1885859012e04/
>
> http://groups.google.com/group/microsoft.public.dotnet.framework.sdk/browse_
> thread/thread/7e4ef4494d9285bb/
>
> Hope this helps.
>
> Sincerely,
> Walter Wang (waw***@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications. If you are using Outlook Express, please make sure you clear the
> check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
> promptly.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>

AddThis Social Bookmark Button