468,457 Members | 1,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

Map Network Drive

How can I have my network drive in my code.. Like for example X to \\pc1 and
have to type password

Thanks

Nov 20 '05 #1
4 4329
You can use the NetAPI to do so. Chris Dunaway sent me a C# class that had
all of the wrappers for the most common API's but I have it at home... =(

Maybe he can post it here or email it to you.

-cJ

"Carlos" <cp@swa.com> wrote in message
news:uX**************@TK2MSFTNGP11.phx.gbl...
How can I have my network drive in my code.. Like for example X to \\pc1 and have to type password

Thanks

Nov 20 '05 #2
Try

System.Diagnostics.Process.Start("net", "use h: \\tower1\newpublic")

Catch ex As Exception

MessageBox.Show(ex.ToString)

End Try

Regards OHM

"Carlos" <cp@swa.com> wrote in message
news:uX**************@TK2MSFTNGP11.phx.gbl...
How can I have my network drive in my code.. Like for example X to \\pc1 and have to type password

Thanks

Nov 20 '05 #3
* "Carlos" <cp@swa.com> scripsit:
How can I have my network drive in my code.. Like for example X to \\pc1 and
have to type password


Sure you had a look here?

<URL:http://groups.google.de/groups?as_q=dotnet+map+network+drive+-herfried>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
Hi Carlos,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to add a map network in
VB.NET.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

We can use the WNetAddConnection2 API, here goes the code snippet.

<StructLayout(LayoutKind.Sequential)> _
Class NETRESOURCE
Public dwScope As Integer
Public dwType As Integer
Public dwDisplayType As Integer
Public dwUsage As Integer
Public LocalName As String
Public RemoteName As String
Public Comment As String
Public Provider As String
End Class 'NETRESOURCE
Public Declare Function WNetAddConnection2 Lib "mpr.dll" Alias
"WNetAddConnection2A" (ByVal netResource As NETRESOURCE, ByVal password As
[String], ByVal Username As [String], ByVal Flag As Integer) As Integer
Sub Main()
Dim myNetResource As New NETRESOURCE
myNetResource.dwScope = 2 'RESOURCE_GLOBALNET
myNetResource.dwType = 1 'RESOURCETYPE_DISK
myNetResource.dwDisplayType = 3 'RESOURCEDISPLAYTYPE_SHARE
myNetResource.dwUsage = 1 'RESOURCEUSAGE_CONNECTABLE
myNetResource.LocalName = "P:"
myNetResource.RemoteName = "\\sha-dds-01\Products"
myNetResource.Provider = Nothing
Dim ret As Integer = WNetAddConnection2(myNetResource, Nothing,
Nothing, 0)
End Sub
For detailed information about WNetAddConnection2 please refer to the link
below.
WNetAddConnection2
http://msdn.microsoft.com/library/de...us/wnet/wnet/w
netaddconnection2.asp
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Robert Tarantino | last post: by
2 posts views Thread by giloosh99 | last post: by
1 post views Thread by brian.oneil2 | last post: by
8 posts views Thread by Lam | last post: by
3 posts views Thread by Barry Flynn | last post: by
10 posts views Thread by =?Utf-8?B?Z3JlYXRiYXJyaWVyODY=?= | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.