Mapping a network Drive and some other stuff

jack Lindsay

Member
Joined
Nov 27, 2008
Messages
13
Programming Experience
Beginner
Hi Guys.

i need a bit of help..

i am using Visual Basic 2005 Express and i need to map a network drive. i have googled this, but the results i have found dont work, and i dont know why.

if someone could help me by providing a full script that successfully does the mapping. the way i had it working before (using vbs) was input boxes so i could just tell it the drive letter, server and the share, and i would very muchly like this functionallity.

the other things my app will do is create a folder on the remote system (ideally which i can name to what i choose), and then do a copy (prefereably an xcopy) to the remote system

i appreciate any help

Jack
 
Add a reference to Windows Script Host Object Model.

VB.NET:
Dim wshNet As New IWshRuntimeLibrary.WshNetwork
wshNet.MapNetworkDrive("X:", "\\Machine\Path\", True, "domain\username", "password")
...
wshNet.RemoveNetworkDrive("X:\", False, False)

To create a directory look into IO.Directory.CreateDirectory or IO.DirectoryInfo.Create.
 
Hi Matt

Thanks for your help,

when i put the code into vb, it says "IWshRuntimeLibrary.WshNetwork is not defined"

how do i define it?


Thanks

Jack Lindsay
 
In Project menu you find the "Add Reference" menu item, it can also be found in context menu for project item in Solution Explorer.
 
HI,

Well that works a treat. thanks for your help...is it the same for vb 2008?

also, when i use the unmapping bit, it says that wshNet is not declared...does it need to be declared twice?
 
Last edited:
It sounds like your variable scope is too narrow for what you're trying to do. Try declaring it at the class level (right under "Public Class FormX").

I'd advise you to do some reading on scopes in VB.NET
 
Back
Top