473,508 Members | 2,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4482
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3618
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore...
2
5768
by: giloosh99 | last post by:
Hello, Im grabbing tables via VB code using visual foxpro ODBC drives. The tables directory is in a mapped network drive. The code works fine and does the job, however if the computer is idle for...
5
21537
by: Niloday | last post by:
Hi All, I am trying to access a mapped network drive from a service that I have created. The service needs to create/delete folders/files on a network drive. When I tried to connect to a...
1
6552
by: brian.oneil2 | last post by:
Is there a way to install this onto a network file share and allow a team to access it? I would say share a CD from a networked CD drive, but there are multiple CD's that would have to be inserted....
8
11833
by: Lam | last post by:
HI anyone knows how can I open a mapped network file in C#? I try string file = @"T:\file.txt"; it shows me the error: "Could not find a part of the path" but if I copy the file to my C dirve,...
5
4447
by: Nirosh | last post by:
Hi All, Can any one suggest me a best way to do this .. I have a thrid party tool "EXE" that we need to use with our web service to manipulate some complex XML files, which reside in a...
14
2305
by: frostalicious | last post by:
Used VB.NET (on my client PC) to convert VB6 executable to .NET executable. Placed the .exe file on a network drive on my server. From client, ran .NET Wizards "Trust an Assembly" to make the...
2
2659
by: .Net Believer | last post by:
I using the routine below to copy file to a network drive for a regular backup process. Before calling this routine I using another function to check the presence of the LAN connection and the...
3
2678
by: Barry Flynn | last post by:
Hi I am working with a VB 2005 program which has been converted from VB6. It writes data out to a flat file, with code like the following line WriteLine(riFileNo, "Hist", lsAssetID,...
10
10977
by: =?Utf-8?B?Z3JlYXRiYXJyaWVyODY=?= | last post by:
Sorry about that previous one. I pressed enter too early. How does one go about mapping a network drive in C#. i know you use MapNetworkDrive in scripting languages, but i'm not sure how to do it...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.