Windows shares

scandog

New member
Joined
Mar 10, 2006
Messages
2
Programming Experience
Beginner
Hi,

I am new to VB, but need to write a simple program that can transfer files to a windows share over a network.

The problem that I have run into is authentication. How can I send the username and password for the shared folder before I transfer the files?
I don't want to be prompted to enter anything just have the username and password hardcoded in the app.

I am using the \\servername\share for the transfer and it works if I have already mapped the drive on the computer I am sending from.

Thanks for any help

Scandog
 
WSH scripting is available to (temporarily if you wish) map a network drive with credentials. You could also use the Win32 WNet functions, but they are more difficult to use.

WSHNetwork http://msdn.microsoft.com/library/en-us/script56/html/8315df26-d293-4c8d-83cf-05d283df112b.asp

Once you 've done Add Reference (COM page) to Window Script Host Object Model, you can declare an object of WshNetwork like this:
VB.NET:
[COLOR=black][SIZE=2]Dim[/SIZE][SIZE=2] WSHn [/SIZE][SIZE=2]As [/SIZE][SIZE=2]New[/SIZE][SIZE=2] IWshRuntimeLibrary.WshNetwork[/SIZE][/COLOR]

Here is WNet reference http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/wnet/wnet_functions.asp


With a network drive mapped with credentials, it's just to use the System.IO methods and do regular file operations.
 
Sorry to be dumb but the first example looks to be for web base setup. Am I looking at it wrong. The appliation I am trying to build is a stand alone application.

I wouldn't think this should be that complicated. Microsoft must have simple support built in.

I am new to vb most of my work is in php, and java.

Thanks
 
No. Windows Script Host (WSH) is a Windows administration tool. http://msdn.microsoft.com/library/en-us/script56/html/bcde07db-2710-4b5c-badd-875415f1e2cb.asp

Not complicated at all, add reference and two lines of code to map a network drive with credentials:
VB.NET:
[LEFT][COLOR=black][SIZE=2]Dim[/SIZE][SIZE=2] WSHn [/SIZE][SIZE=2]As [/SIZE][SIZE=2]New[/SIZE][SIZE=2] IWshRuntimeLibrary.WshNetwork[/SIZE][/COLOR]
WSHn.MapNetworkDrive("X:", "[URL="file://server/path"]\\server\path[/URL]", False, "User", "Password")[/LEFT]
now you can just copy the local file to drive X:
 
Does the drive show up when you open your explorer? Isn't this kind of hard when you have 100+ users all with different shared maps on your server?

thx
 
Yes, mapped drive show up on client computer (if running in user context, and not for example as windows service).

No, the drive maps are not created at server. The server makes a folder/drive shared and thus makes it available for clients. Clients can map the accessible share to a local drive letter for convenience.
 
Back
Top