Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Thread Tools Search this Thread
Old 14-04-2009
Join Date: Mar 2009
Posts: 60
VBS script to map drives

I am trying to convert some of our scripts over to vbs,network drives are currently being mapped via batch scripts, I have been able to implement several and at one time thought I had compiled enough snippets of code,When the script runs an error message pops up saying "device name already in use".Does anyone know what causes this issue and how to fix it?Any help will be extremely appreciated.
Reply With Quote
Old 14-04-2009
Join Date: Apr 2008
Posts: 2,001
Re: VBS script to map drives

  • Copy and paste the script below into notepad or get a script editor such as OnScript .
  • Change the server name from "\\alan to the name of your server.
  • Check the share name '\home'.
  • Save the file with a .vbs extension, e.g. MND.vbs or MapNetworkDrive.vbs.
  • Double click the resulting script and look in your Windows Explorer for a new drive letter.

Set objNetwork = CreateObject("WScript.Network") 
objNetwork.MapNetworkDrive "H:" , "\\alan\home"
Reply With Quote
Old 14-04-2009
Join Date: May 2008
Posts: 2,383
Re: VBS script to map drives

The script below maps drives for uses in two ways. First off, it will give all users the default shares and there home drive (P, S, X).

Then it checks what groups a user is a member of and attaches the appropriate drives. (W, U, Z, M, L)

Drives M, L attach to another server and also use different logon credentials. If you required another drive with different credentials, you could try…

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path, objNetwork, objNetwork1

Add another value “objNetwork2”

Then find in the script below and copy and paste it to a new section. Then replace all the 1’s with 2’s.

Amend the username, password and the share to reflect the desired connection. And fingers crossed it should work.
Set objNetwork1 = WScript.CreateObject("WScript.Network")
strLocalDrive1 = "L:"
strRemoteShare1 = "\\server\share"
strPer1 = "FALSE"
strUsr1 = "username"
strPas1 = "password"
objNetwork1.MapNetworkDrive strLocalDrive1, strRemoteShare1, strPer1, strUsr1, strPas1
Reply With Quote
Old 14-04-2009
Join Date: Feb 2008
Posts: 1,848
Re: VBS script to map drives

This code creates a mapped drive to a network path.

strDrive = "<Drive>" ' e.g. N:
strPath = "<Path>" ' e.g. \\rtp01\c$\temp
strUser = "<User>" ' e.g. AMER\rallen
strPassword = "<Password>"
boolPersistent = True ' True = Persistent ; False = Not Persistent

' ------ END CONFIGURATION ---------
set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDrive, strPath, boolPersistent, _
strUser, strPassword
WScript.Echo "Successfully mapped drive"
Reply With Quote

  TechArena Community > Software > Software Development
Tags: , , ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "VBS script to map drives"
Thread Thread Starter Forum Replies Last Post
My Windows XP laptop has stopped recognising/working with my external hard-drives and USB flash-drives HowlCat Operating Systems 1 30-09-2011 12:00 PM
.bat script for reconnecting net drives gutts Networking & Security 2 20-04-2011 06:33 PM
Logoff Script for Dissconnecting Mapp Drives . mypass604 Operating Systems 2 16-10-2009 09:10 AM
Removing and remapping network drives using logon script jacobscharlene Software Development 1 17-12-2008 03:43 PM
Unable to map drives with logon script c54618 Windows Server Help 5 03-05-2008 07:10 PM

All times are GMT +5.5. The time now is 08:13 PM.